list tips

We can take lists apart using CAR and CDR("first" and "rest") and put them togetherwith CONS or LIST. The LENGTH function counts the number of elements in a list,which is the same as its number of top-level cons cells.

The important points about CAR and CDR are:

1.CAR and CDR accept only lists as input.

2.FIRST and REST are the same as CAR and CDR.

3.SECOND and THIRD are the same as CADR and CADDR.

4.Common Lisp provides built-in C...R functions for all combinations of CAR and

   CDR up to and including four As and Ds.

The symbol NIL has several interesting properties:

1.NIL is a symbol. It is the only way to say "no" or "false" in Lisip.

2.NIL is the only Lisp object that is both a symbol and a list.

3.NIL marks the ends of a cons cell chain. When lists are printed in parenthesis

notation, theNILs at the end of chains are omitted by conversion.

4.NIL and () are intechangeable notations for the same object.

5.The CAR and CDR of NIL are defined to be NIL.


Functions covered in this chapter 2

List functions : FIRST,SECOND,THIRD,FOURTH,REST,CAR,CDR,CONS,LIST,LENGTH

Compositons of CAR and CDR:CAR CADDR,and so on.

Predicates: LISTP,CONSP,ATOM,NIL.

The NULL predicate returns T if its input is NIL. Its behavior is the same as the NOT 

predicate. By convention,Lisp programmers reserver NOT for logical operations:

changing true to false and false to true.They use NULL when they want to test whether a list is empty.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值