问题
I'm trying to understand the relations between pair, cons, dotted tuples and proper list in PLT-Scheme 372. The detailed context of my question is as follows:
After reading some textbook and doing trial-and-error, I have got the following understanding and intuitive ideas (I may be wrong...):
all lists are pairs, e.g.:
(pair? (list 'a 'b 'c)) => #t
all conses are pairs, e.g.:
(pair? (cons 'a (cons 'b 'c))) => #t
some dot-separated tuples are pairs, e.g.:
(pair? '(a . b)) => #t
(pair? '(a . b . c)) => #t
in Standard R5RS it's not legal syntax.
Then I bumped into this problem: Why does '(a . b . c) evaluate to (b a c)? Where can I find a complete usage manual of dot?
'(a . b) => (a . b)
'(a . b . c) => (b a c)
'(a . b . c . d) => illegal use of `.'
'(cons 'a (cons 'b 'c)) => (a b . c)
回答1:
For Racket (PLT), there is a good description here.
Regarding the syntax (a . b . c)
look at the bottom of the page, it's a Racket-specific reader extension designed to express typical tests like (< 1 2)
as (1 . < . 2)
.
来源:https://stackoverflow.com/questions/20816353/why-does-a-b-c-evaluate-to-b-a-c-in-plt-scheme-372