1.参考资料
the scheme programming language 4th
the little schemer
2. scheme诞生于1975年,是一种lisp方言。通用型语言,用途遍及it领域。
3.关于变量
变量名的第一个字母不能是"@"符号,不能是数字,不能是"+" "-" "."这三个。注意,单独的"+" "-"和"..."是有效变量名,且"->"开头的变量名也是有效的。区分大小写。
4.数据类型
表,例如 (a b c)。空表 () 。向量vector跟表差不多,第一个字母是#,例如#(this is a vector of symbols)。字节向量 #vu8 (3 250 45)
字符串"I am a string"。字符,例如 #\a
bool变量 #t 和#f,注意,#f是false,其他所有的对象都是true,比如 3,0,(),"falese"和nil都是#t
还有其他各种类型,不一一叙述,用的时候就知道了。
5.安装scheme
apt-get install mit-scheme
然后在命令行运行 scheme,进入交互界面,输入(+ 1 2)回车,得到3。
6.写一个文本文件写一个函数,然后在scheme里导入,并执行
6.1 写一个文件"reci.ss",内容如下
(define recip
(lambda (n)
(if (= n 0)
"oops!"
(/ 1 n)
)
)
)
6.2 启动scheme,在里面执行
(load "/home/tt/rec.ss")
然后执行(recip 0)
再执行(recip 3)
7. quote
(a b c),其中,a如果是一个函数名,那么这就是一个函数调用,如果a是字符,这就是一个list。所以无法区分函数调用还是符号。另外,(+ a b)有时候需要被视为符号,而不是加法计算。因此,如果要视为符号,都一概写成(quote (+ a b)),简写是'(+ a b)。
8.计算一个表达式的值,比如,(procedure arg1 arg2 arg3),计算过程是,查找procedure的值,查找arg1的值,查找arg2的值,查找arg3的值,讲procedure应用apply到arg1,arg2和arg3上,得到结果。
9.let,给一个变量赋值,然后再计算结果(let ((x 2)) (+ x 3)),结果是5,也可以给多个变量赋值,比如(let ((x 2) (y 3)) (+ x y))。let可以有很复杂的用法。
10.define和lambda定义函数 (define doubler (lambda (f) (lambda (x) (f x x))))
11.p43 递归