the little schemer 笔记(1)
第 1 章 玩具
这是原子atom吗?
atom
是的,因为atom是一个字母a开头的字符串。
这是原子atom吗?
turkey
是的,因为atom是字母开头的字符串。
这是原子atom吗?
1492
是的,因为1492是数字的字符串。
这是原子atom吗?
u
是的,因为u是字母开头的字符串,仅仅一个字符。
这是原子atom吗?
*abc$
是的,因为atom是字母或者除了括号”(“和“)”外的特殊字符开头的字符串。
这是list表吗?
(atom)2
是的,因为(atom)是一个atom原子外加括号构成。
这是list表吗?
(atom turkey or)
是的,因为它是由一组原子外加括号构成。
这是list表吗?
(atom turkey) or
不是,这是两个没有括起来的两个S-expression表达式,第一个是含有两个atom原子list列,第二个是一个atom原子。
这是list表吗?
((atom turkey) or)
是的,因为这是两个S-expression表达式外加括号构成。
这是S-expression吗?
xyz
是的,因为所有的atom原子都是S-expression表达式。
这是S-expression吗?
(x y z)
是的,因为它是一个list列表。
这是S-expression吗?
((x y) z)
是的,因为所有的list表都是S-expression表达式。
这是list吗?
(how are you doing so far)
是的,因为它是S-expression表达式外加括号组成的。
list表中有多少个 S-expression?
(how are you doing so far)
六个,how, are, you, doing, so, 和far。
这是list吗?
(((how) are) ((you) (doing so)) far)
是的,因为它是S-expression表达式外加括号组成的。
list表中有多少个 S-expression?
(((how) are) ((you) (doing so)) far)
三个,((how) are), ((you) (doing so)), 和 far
这是list吗?
()
是的,因为它是0个S-expression表达式外加括号组成的。这个特殊的S-expression称为null空(或者empty空)
这是atom原子吗?
()
不是,因为()仅仅是一个list表。
这是list吗?
(() () () ())
是的,因为它是S-expression表达式外加括号组成的。
下面的声明中的表l的car是什么
(a b c)
是a,因为a是list表的第一个atom原子
下面的声明中的表l的car是什么
l是((a b c) x y z)
(a b c), 因为(a b c)是这个非空list表的第一个 S-expression表达式。
下面的声明中的表l的car是什么
l是 hotdog
没有答案,atom原子没有car
下面的声明中的表l的car是什么
l是 ()
没有答案,空表没有car。 注脚:L:nil
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Car的规则
基本操作符car仅为非空list表定义。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
下面的声明中的表l的car是什么
l是(((hotdogs)) (and) (picle) relish)
((hotdogs)),叫做“hotdogs的列表的列表。”((hotdog))是l的第一个 S-expression.
下面的声明中的表l,取(car l)是什么
l是(((hotdogs)) (and) (picle) relish)
((hotdogs)), (car l)是另一种“l的car”的写法。
示意:
(car ( ((hotdogs)) (and) (picle) relish))
==> ((hotdogs))
下面的声明中的表l的(car (car l))是什么
l是(((hotdogs)) (and))
(hotdogs)。示意为:
(car (car (((hotdogs)) (and))))
==>(car ((hotdogs)) )
==> (hotdogs)
下面的声明中的表l的cdr是什么
l是(a b c)
(b c), 因为(b c)是l中除了(car l)的部分。
注意:“cdr”发音为“could-er”。
下面的声明中的表l的cdr是什么
l是((a b c) x y z)
(x y z).
下面的声明中的表l的cdr是什么
l是(hamburger)
()。
下面的声明中的表l,取(cdr l)是什么
l是((x) t r)
(t r),因为(cdr l) 仅仅“表l的cdr“的另一种表示方法。
下面的声明中的表l的cdr是什么
l是 hotdogs
没有答案,atom原子没有cdr。
下面的声明中的表l的cdr是什么
l是()
没有答案,空表null没有cdr。
练习:(null? alpha)除了空表外都为假。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cdr的规则
基本操作符cdr仅为非空list表定义。任何非空list的cdr都是另一个list。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
下面的声明中的表l,取(car (cdr l))是什么
l是((b) (x y) ((x)))
(x y), 因为((x y) ((c)))是(cdr l), (x y) 是(cdr l)的car。示意:
(car (cdr ((b) (x y) ((x)))))
==>(car ( (x y) ((x)))))
==> (x y)
下面的声明中的表l,取(cdr (cdr l)) 是什么
l是((b) (x y) ((x)))
(((x))), 因为((x y) ((c)))是(cdr l),而(x y)是(cdr l)的car。
示意:
(cdr (cdr ((b) (x y) ((x)))))
==>(cdr ( (x y) ((x)))))
==> ( ((x)) )
下面的声明中的表l,取(cdr (car l))
l是(a (b (c)) d)
没有答案,因为(cdr l)是一个atom原子,它不能取cdr了。
car 的参数可以是什么
任何非空list表。
cdr 的参数可以是什么
任何非空list表。
假设a是 peanut,l是(butter and jelly),那么a和l的cons(这通常写作"(cons a l)",读作把atom原子a cons到list表l上)是什么
(peanut butter and jelly),因为cons把一个atom原子追加到list表最前头。
示意:
(cons a (butter and jelly)
==>(peanut (butter and jelly)
假设s是(banana and),l是(peanut butter and jelly),那么把scons到l上是什么
((banana and) peanut butter and jelly),因为cons任意 S-expression追加到list表最前头。
示意:
(cons (banana and) (peanut butter and jelly) )
==> ((banana and) peanut butter and jelly)
假设s是((help) this),l是(is very ((hard) to learn)),那么(cons s l) 是什么
(((help) this) is very ((hard) to learn))。
示意:
(cons ((help) this) (is very ((hard) to learn)) )
==> (((help) this) is very ((hard) to learn))
cons 的参数可以是什么
cons带两个参数,第一个可以是任何 S-expression,第二个是任意list表。
假设s是 (a b (c), l是(),那么 (cons s l) 是什么
((aa b (c)))
假设s是 a, l是(),那么 (cons s l) 是什么
(a)
假设s是 ((a b c)), l是b,那么 (cons s l) 是什么
没有答案,因为l不是list不能cons。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cons的规则
基本操作符cons有两个参数。cons的第二个参数必须是list表,结果返回一个list表。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
假设s是a,l是((b) c d),那么(cons s (car l))是什么
(a b)
示意:
(cons a (car ((b) c d) ))
==>(cons a (b) )
==> (a b)
假设s是a,l是((b) c d),那么(cons s (cdr l))是什么
(a c d)。
示意:
(cons a (cdr ((b) c d) ))
==>(cons a ( c d) )
==> (a c d)
假设l是(),那么l是null list表,对么
是的,因为它是一个含有0个 S-expression表达式的list列表。
(null? (quote ()) 是什么
true真。因为(quote())是空表null的写法。
注:L:空表可以是()或者'(),S:可以是'()。是否是空表,L:null。
假设l是(a b c),那么(null? l)是真还是假
假。L是非空集。
假设A是SPAGHETI,那么(NULL? A)是真还是假
没有答案,ATOM原子没有真假。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Null的规则
基本操作符null?仅仅为list表定义
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
假如s是harry,那么s是否是atom原子
真。因为harry是字母开始的字符串。
如果 s 是 harrry 那么(atom? s)是什么
真。因为 (atom? s) 是另外一种表达”s是否是一个atom原子“的方式。
注:
L:(defunation? (x)
(not (listp x)))
S:(define atom?
(lambda (x)
(and (not (pair? x)) (not (null? x))))
假如s是 (Harry had a heap of apples),那么 (atom? s) 是真是假
假。因为s是一个list表。
atom?有几个参数
一个。这个参数可以是任意 S-expression。
假如s是 (Harry had a heap of apples),那么 (atom? (car l)) 是真是假
真。
示意:
(atom? (car (Harry had a heap of apples))
==>(atom? Harry )
==>true
假如s是 (Harry had a heap of apples),那么 (atom? (cdr l)) 是真是假
假。
示意:
(atom? (cdr (Harry had a heap of apples) ) )
==>(atom? (had a heap of apples) )
==>false
假如s是 (swing low sweet cherry oat) ,那么 (atom? (car (cdr l))) 是真是假
真。
示意:
(atom? (car (cdr (swing low sweet cherry oat))))
==>(atom? (car (low sweet cherry oat)) )
==>(atom? low ) )
==>true
假如s是 (swing (low sweet) cherry oat) ,那么 (atom? (car (cdr l))) 是真是假
假。
示意:
(atom? (car (cdr (swing (low sweet) cherry oat))))
==>(atom? (car ((low sweet) cherry oat)) )
==>(atom? (low sweet) )
==>false
假如 a1是 Harry,a2是 Harry,那么 a1和a2 是否相等
真。因为a1和a2完全相同。
假如 a1是 Harry,a2是 Harry,那么 (eq? a1 a2) 是真还是假
真。因为 (eq? a1 a2) 是另外一种表达”a1和a2是否是同一个非数值atom原子“的方式。
注:Lisp:eq
假如 a1是 margarine,a2是 butter,那么 (eq? a1 a2) 是真还是假
假。a1和a2不同。
eq?需要多少参数?各是什么?
两个参数,都是非数值atom原子。
假设l1是(),l2是 (strawberry),那么 (eq? l1 l2)是真还是假
没有答案,()和(strawberry)是list表。
注:实际当中是可以作为eq?的参数的。
假设n1是6,n2是7,那么 (eq? n1 n2)是真还是假
没有答案,因为两个参数是数字。
注:实际当中是可以作为eq?的参数的。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eq?的规则
基本操作符eq?带有两个参数,两个都是非空数值的atom原子
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
假设l是 (Mary had a little lamb chop),a是 Mary,那么(eq? (car l) a) 是真还是假
真。
假设l是 (soured milk),a是 Mary,那么(eq? (cdr l) a) 是真还是假
没有答案。
假设l是 (beans beans we need jelly beans),(eq?(car l) (car (cdr l))) 是真还是假
真。因为这是在比较list表中的第一个和第二个atom原子。
==>现在去,做出自己的花生酱果冻三明治<==

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 China Mainland License.
the little schemer 笔记(1)的更多相关文章
- the little schemer 笔记(0)
the little schemer 笔记 Z.X.L 2012年08月13日 五项规则 car的规则car只对非空列表有定义. cdr的规则cdr只对非空列表有定义.任何非空列表的cdr是另外一个列 ...
- the little schemer 笔记(10)
第十章 What Is the Value of All of This? entry条目 是由list表组成的 pair 对,pair 对的第一个list表是集合 set.另外,两个list表的长 ...
- the little schemer 笔记(3)
第三章 cons the magnificent (rember a lat)是什么,其中a是mint,lat是(lamb chops and mint jelly) (lamb chops and ...
- the little schemer 笔记(10.1)
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 China Mainla ...
- the little schemer 笔记(9)
第九章 ...and Again, and Again, and, Again, ... 你想来点鱼子酱吗? 那就去找它吧. (looking a lat)是什么,其中a是 caviar, lat是( ...
- the little schemer 笔记(8)
第八章 lambda the ultimate 还记得我们第五章末的rember和insertL吗 我们用equal?替换了eq? 你能用你eq?或者equal?写一个函数rember-f吗 还不能, ...
- the little schemer 笔记(5)
第五章 “Oh My Gawd”:It's Full of Stars (rember* a l)是什么,其中a是cup,l是((coffee) cup ((tea) cup) rember*发音为r ...
- the little schemer 笔记(7)
第七章 Friends and Relations 这是一个set集合吗 (apple peaches apple plum) 不是,apple出现了不止一次 (set? lat) 是真还是假,其中l ...
- the little schemer 笔记(6)
第六章 Shadows 1 是算术表达式吗 是 3 是算术表达式吗 是的 1+3 是算术表达式吗 是的 1+3×4 是算术表达式吗 当然是 cookie 是算术表达式吗 是啊,你需要来一块吗 e那么 ...
- the little schemer 笔记(4)
第四章 numbers games 14 是原子吗 是的,数都是原子 (atom? n) 是真还是假,其中n是14 真,14 是原子 -3是数吗 是的,不过我们暂不考虑负数 3.14159是数吗 是的 ...
随机推荐
- android 编程小技巧(持续中)
first: Intent跳转一般存用于Activity类,可是若要在非activity类里跳转的话,解决方法是在startActivity(intent)前加mContext即上下文,终于为 ...
- HashMap存入大量数据是否要预定义存储空间
按说HashMap的负载极限为0.75,可是,测试程序并看不出这个结果.待探讨 测试程序如下: 根据结果看不出来预定义有什么影响. public class test { public static ...
- js replace()实现全部替换
var r= "1\n2\n3\n"; //将字母\n替换成分号 alert(r.replace("\n",";")); 结果:1;2\n3 ...
- mysql数据库引擎InnoDB和MyISAM的区别
InnoDB支持行级锁和表级锁(默认行级锁),支持事务,外部键等:大量的insert和update更快等.只有通过索引条件检索数据,InnoDB 才使用行级锁,否则,InnoDB 将使用表锁. MyI ...
- HDU1358 Period —— KMP 最小循环节
题目链接:https://vjudge.net/problem/HDU-1358 Period Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- 如何查看一个Application是32位的还是64位的?
使用process explorer查看,找到对应的进程. 注册表的路径是Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ 使用powershell查 ...
- PLSQL 安装说明
PLSQL安装说明. 1.安装oracle 11g ,2030端口设置防火墙例外.2.PLSQL Developer 9.0.0.1601是绿色版,复制到本地即可.3.PLSQL->Tools- ...
- Python之如果添加扩展包
1.首先下载好你需要的扩展包 下载地址是http://www.lfd.uci.edu/~gohlke/pythonlibs/ 2.将你下载好的.whl文件放在你的python文件夹中的Lib\site ...
- C语言变量声明问题——变量定义一定要放在所有执行语句/语句块的最前面吗?
报错信息:error C2065: 'salary' : undeclared identifier #include <stdio.h> void main(){ printf(&quo ...
- CoreOS,CoreOS,一款 Linux 容器发行版
CoreOS,一款最新的 Linux 发行版本,支持自动升级内核软件,提供各集群间配置的完全控制. 关于使用哪个版本的 Linux 服务器系统的争论,常常是以这样的话题开始的: 你是喜欢基于 Red ...