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!
(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. :-)
精彩评论