开发者

Definition of a list in Scheme

Finally taking the plunge to learn a Lisp dialect (Scheme), I have encountered two definitions of a list -

&qu开发者_高级运维ot;Either the empty list or a pair whose cdr is a list".

"A collection of S-Expressions enclosed by parentheses".

Are these definitions equivalent?


They're as equivalent as {'a','b','c'} and "abc"

The former is the machine's logical representation of a list, the latter is how you represent it in your code.

And in scheme, you can pretty much treat everything as a list :) (Someone's going to downvote me for that, but I found it to be true when trying to think scheme-esque.)


I'm going to bring out my favourite dog-and-pony show!

Definition of a list in Scheme


(source: hedgee.com)

This corresponds to the following:

(let ((s5 (sqrt 5)))
  (/ (- (expt (/ (1+ s5) 2) n)
        (expt (/ (- 1 s5) 2) n)) s5))

The diagram illustrates your first statement (the empty-list object is denoted as a black box). The code snippet illustrates your second. :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜