Lisp-Fire Rules

Lisp编程的五条基本规则:

Law of car

  The primitive car is defined only for non­empty lists.

Law of cdr:

  The primitive cdr is defined only for non­empty lists. The cdr of any nonempty list is always another list.

Law of cons:

  The primitive cons takes two arguments. The second argument to cons must be a list. The result is a list.

The Law of Null?

  The primitive null? is defined only for lists.

The Law of Eq?

  The primitive eq? takes two arguments. Each must be a non-numeric atom.

 

这五条规则描述了Lisp基本编程法则。Lisp是一种函数式编程语言,car, cdr, cons, null?, eq? 就是Lisp下五个最基本的函数,这五条规则实际上描述了这五个函数的基本用法以及返回的结果。

在Lisp中有两个基本的概念:一个时atom,另一个是list。它们是Lisp下两种基本的数据结构,atom可以是一个字符,也可以是一个字符序列。list当然就是一个列表,列表中的每一个元素都可以是一个atom或者一个列表。这里就可以看到Lisp中一个很重要的概念:递归。显然,list是一种递归的数据结构,atom可以看作是list递归结束的“条件”。

posted @ 2012-08-12 18:37  hi_fly  阅读(343)  评论(0编辑  收藏  举报