[scheme-001] 最简scheme教程 001

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))))

(define abs (lambda (x) (if ( < n 0) (- 0 n) n)))

11.p43 递归



Scheme is a general-purpose programming language, descended from Algol and Lisp, widely used in computing education and research and a broad range of industrial applications. This thoroughly updated edition of The Scheme Programming Language provides an introduction to Scheme and a definitive reference for standard Scheme, presented in a clear and concise manner. Written for professionals and students with some prior programming experience, it begins by leading the programmer gently through the basics of Scheme and continues with an introduction to some of the more advanced features of the language. The fourth edition has been substantially revised and expanded to bring the content up to date with the current Scheme standard, the Revised6 Report on Scheme. All parts of the book were updated and three new chapters were added, covering the language's new library, exception handling, and record-definition features. The book offers three chapters of introductory material with numerous examples, eight chapters of reference material, and one chapter of extended examples and additional exercises. All of the examples can be entered directly from the keyboard into an interactive Scheme session. Answers to many of the exercises, a complete formal syntax of Scheme, and a summary of forms and procedures are provided in appendixes. The Scheme Programming Language is the only book available that serves both as an introductory text in a variety of courses and as an essential reference for Scheme programmers.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值