문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top