This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* TreePost.java | |
* | |
* | |
* | |
* Copyright (C) 2012-10-25 liutos | |
*/ | |
class TreeNode | |
{ | |
char value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* postorder_output.c | |
* | |
* Generates a binary tree according to the two outputs of preorder and | |
* inorder traversal and outputs a sequence of nodes by postorder traversal. | |
* | |
* Copyright (C) 2012-10-25 liutos <[email protected]> | |
*/ | |
#include <stdlib.h> | |
#include <string.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* main.c | |
* | |
* | |
* | |
* Copyright (C) 2012-10-01 liutos | |
*/ | |
#include "type.h" | |
#include <stdio.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; Code Examples but the language wasn't implemented yet. | |
;;; 定义函数factorial | |
defun factorial (n) ;; 注释以两个分号开始,至一行的末尾结束。 | |
if 0 = n ;; 表示两个对象之间的关系的函数用中缀形式表示 | |
1 | |
n * factorial(n - 1) ;; if的alternate部分的表达式比起consequence的部分向左移动一个空格,但是其实并非像Python那样用缩进决定语法结构。 | |
;;; 尾递归版本的factorial,使用了内部的辅助函数。 | |
;;; 可以这样表达的内部函数需要语言支持词法作用域,并且defun也应该是这样的,而不是像CL那样定义全局函数。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let maxSubseq seq = | |
let aux = Array.create (Array.length seq) 0 | |
and len = Array.length seq | |
and iStart = ref 0 | |
and iEnd = ref 0 | |
and max = ref 0 | |
in | |
begin | |
aux.(0) <- seq.(0); | |
max := seq.(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defpackage :com.liutos.editance | |
(:use :cl)) | |
(in-package :com.liutos.editance) | |
(defmacro for ((var start end) &body body) | |
`(do ((,var ,start (1+ ,var))) | |
((> ,var ,end)) | |
,@body)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defpackage :com.liutos.max-incseq | |
(:use :cl) | |
(:nicknames :max-incseq) | |
(:documentation "计算一个序列的最长递增子序列")) | |
(in-package :max-incseq) | |
(defun max-incseq/aux (vec) | |
"返回中间结果的数组,存储了到达各个数的最长递增子序列的长度。" | |
(declare (type vector vec)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defpackage :com.liutos.del0-interp | |
(:use :cl) | |
(:nicknames :del0-interp | |
:interp)) | |
(in-package :interp) | |
(defvar *env0* '()) | |
(defun ext-env (x v env) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 下面的函数定义中参数c没有使用到,在我的系统上使用SBCL,在TopLevel中输入下面的表达式会抛出警告,说变量c没有使用。 | |
(defun my-plus (a b c) | |
(if (zerop b) | |
a | |
(my-plus (1+ a) (1- b) nil))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 这是《Lisp in Small Piece》上第9页的eprogn函数的定义,实际上这样子的定义 | |
;;; 是为了可以让调用eprogn的返回值可以是最后一个被求值的表达式。 | |
(define (eprogn exps env) | |
(if (pair? exps) | |
(if (pair? (cdr exps)) | |
(begin (evaluate (car exps) env) | |
(eprogn (cdr exps) env)) | |
(evaluate (car exps) env)) | |
'())) |