scheme语言的可读性??
关键字: FP看到sicp的第2章,突然又想做做题了,一般我是有兴趣才做一下,
Exercise 2.4. Here is an alternative procedural representation of pairs. For this representation, verify that (car (cons x y)) yields x for any objects x and y.
(define (cons x y)
(lambda (m) (m x y)))
(define (car z)
(z (lambda (p q) p)))
What is the corresponding definition of cdr?
挺容易得到正确答案的,
(define (cdr z)
(z (lambda (p q) q))) 把p换成q就可以了,可以想通可费了点时间,呵呵
需要置换进去才知道是怎么回事,呵呵
以car为例
定义个 pair
(define x (cons 12 34))
当调用(car x) 的时候
置换进去,实际上就是
( (lambda (m) (m 12 34)) (lambda (p q) p))
继续,根据语法
(lambda (p q) p)就是前面 (lambda (m) (m 12 34))的参数了,
是参数就代入看看
函数体(m 12 34) 变为 ((lambda (p q) p) 12 34)
哈哈,12 34又变成(lambda (p q) p)的参数了,
结果 12就出来,绕口吧,^_^,无聊的时候做做题目挺开心的。
要是实际项目写这样的代码,有人读吗,
评论
zhuyi8319 写道:
结果 12就出来,绕口吧,^_^,无聊的时候做做题目挺开心的。
要是实际项目写这样的代码,有人读吗,
拜托,这段代码不是无聊的游戏,是用来表示可以用procedure来表示data
This may seem a curiosity now, but procedural representations of data will play a central role in our programming repertoire. This style of programming is often called message passing, and we will be using it as a basic tool in chapter 3 when we address the issues of modeling and simulation.
丘奇数实在是天才的灵感。
zhuyi8319 写道:
结果 12就出来,绕口吧,^_^,无聊的时候做做题目挺开心的。
要是实际项目写这样的代码,有人读吗,
无语。这是lambda演算的一部分。书上说了,list真的可以这样实现。
你看到后面,还有一个变态的"T变换",以及超变态的"丘奇计数",也是类似的东西。
顺便说一下,昨天看到一个OCaml Tutorial的wiki文档,作为入门学习好像不错的,在 http://www.ocaml-tutorial.org/
那个Tutorial的中文翻译正在展开中。http://ocaml.cn 上也有不少资料。
http://www.realworldhaskell.org/blog/
顺便说一下,昨天看到一个OCaml Tutorial的wiki文档,作为入门学习好像不错的,在 http://www.ocaml-tutorial.org/
http://www.kamang.net/
当初搞haskell,也是感觉不爽,后面感觉蛮好的。
想问问后来用haskell写了实际程序吗?我在想它的适用范围,或者更擅长于做什么事情。
当初搞haskell,也是感觉不爽,后面感觉蛮好的。
http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/41c23db25ddcd899/5578f0f9ffff7839#5578f0f9ffff7839
- 浏览: 12127 次
- 性别:

- 来自: 北京

- 详细资料
搜索本博客
最新评论
-
scheme语言的可读性??
lambda (m) (m x y)换成Z就出来了的
-- by ychael -
scheme语言的可读性??
zhuyi8319 写道: 结果 12就出来,绕口吧,^_^,无聊的时 ...
-- by javaeye000 -
scheme语言的可读性??
Joard推荐的文章里的Scheme程序就很好读阿。特别是实现矩阵转置和list ...
-- by codemonkey -
换零钱问题
zhuyi8319 写道我在大学讲递归的时候,用的是 八皇后,呵呵,当时觉得很难 ...
-- by 抛出异常的爱 -
scheme语言的可读性??
是比较无语,楼主没搞清楚书中想表达什么,扯到可读性上去了。。。 丘奇数实在是天才 ...
-- by dennis_zane






评论排行榜