Lisp-Ten Commandments

这十条戒律因该说是在进行Lisp编程时,需要引起格外注意的地方,否则便有可能引入错误。很有意思呢。。不太好翻译,还是英文原文表达的简洁易懂一些。所以摘录如下:

第一戒:

When recurring a list of atom, lat, ask two questions about it: (lat? l) and else.

When recurring on a number, n, ask two questions about it: (zero? n) and else.

When recurring on a list of S-expressions, l, ask three question about it: (null? l), (atom? ( car l)), and else.

 

第二戒:

Use cons to build lists.

 

第三戒:

When building a list, describe the first typical element, and then cons it onto the natu­ral recursion.

 

第四戒:

Always change at least one argument while recurring.

When recurring on a list of atoms, lat, use (cdr lat).

When recurring on a num­ber, n, use (sub1 n).

When recurring on a list of S-expressions, l, use (carl) and (cdr l) if neither (null? l) nor (atom? (carl)) are true.

 

第五戒:

When building a value with + ,always use 0 for the value of the terminating line, for adding 0 does not change the value of an addition.

When building a value with x, always use 1 for the value of the terminating line, for multiplying by 1 does not change the value of a multiplication.

When building a value with cons, always consider () for the value of the terminating line.

 

第六戒:

Simplify only after the function is correct.

 

第七戒:

Recur on the subparts that are of the same nature:
On the sublists of a list.
On the subexpressions of an arithmetic expression.

 

第八戒:

Use help functions to abstract from representation.

 

第九戒:

Abstract common patterns with a new function.

 

第十戒:

Build functions to collect more than one value at a time.

转载于:https://www.cnblogs.com/hiflex/archive/2012/08/12/Lisp_10_commandments.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值