问题
Given
#;> (cons (cons 1 2) 3)
((1 . 2) . 3)
When we try
#;> (cons 3 (cons 1 2))
(3 1 . 2)
What governs where the .
is used? What would the memory representation of these constructs be?
回答1:
Scheme implementations usually print things that look like lists in list form:
-> (cons 1 (cons 2 '()))
'(1 2)
In your example, (cons 3 (cons 1 2))
would be a list if it weren't for the last 2
. So your implementation makes a best effort to print it as a list until the 2
. The other example does not contain any part that looks like a list, so it just prints as nested pairs.
来源:https://stackoverflow.com/questions/14289439/on-scheme-cons-and-dots-notation