像处理数据一样处理代码

来源:互联网 发布:mac bt下载工具 编辑:程序博客网 时间:2024/05/21 09:37

只听Norvig说:“是,John,你有什么问题?”我记不清Lisp之父当时怎么问的了,但不超过十个词,就是问 Python是否能如Lisp那样优雅地像数据一样处理代码。“不,John,不行。”Norvig回答,然后静等麦卡锡继续发问。但是,老人什么也没有再说。

怎么样像处理数据一样处理代码?

(define (cons x y)  (define (dispatch m)    (cond ((= m 0) x)  ((= m 1) y)  (else (error))))  dispatch)(define (car z) (z 0))(define (cdr z) (z 1))

This example demonstrates that the ability to manipulate procedures as objects automatically provides the ability to represent compound 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 calledmessage passing.


参考文献:《structure and interpretation of computer programs》

原创粉丝点击