The Little Schemer-CHP2、3、4

CHP2

(cond ...) 功能为判断;
(lambda (var...) exp) 创建一个含参数var...的过程,具体内容由exp决定;
(define var exp) 定义一个新变量,并把exp的求值结果赋给它;

规则一

在任何过程中,总是先判断是否为空表(null?)。

CHP3

规则二

使用cons构建列表(list)。

规则三

当构建列表(list)时,先拿到特有元素(typical element),然后cons它到传统递归(natural recursion)上。

(cons (car lat) (insertL new old (cdr lat)))
规则四

当递归时,至少要改变一个参数,并该参数要不断地向终止条件靠近,同时该参数要用于终止条件的判断中。

  • 当使用cdr时,终止条件用null?
  • 当使用sub1时,终止条件用zero?

The First Commandment: Always ask null? as the first question in expressing any function.

The Second Commandment: Use cons to build lists.

The Third Commandment: When building a list, describe the first typical element,and then cons is onto the natural recursion.

The Fourth Commandment: Always change at least one argument while recurring. It must be changed to be closer to termination. The changing argument must be tested int the termination condition; when using cdr, test termination with null?

CHP4

元组(tuple)

它是一个由数字组成的元素集合。


The Five Rules

The Ten Commandments
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 第一部分Common Lisp介绍第1章 介绍一下Lisp你在学的时候觉得已经明白了,写的时候更加确信了解了,教别...
    geoeee阅读 8,161评论 5 8
  • 我们要停下来,谈谈抉择那些事 每个人一辈子要做无数次抉择,每个抉择通过一条神奇的公式不断的给我们反馈或正面或负面的...
    简书Kyle阅读 6,700评论 3 45
  • (一) 在那个青黄不接的年代,改革开放的春风吹透了城市,吹透了城镇,终于吹进了王家...
    多肉爱吐槽阅读 3,909评论 17 9