On Scheme cons and dots notation

好久不见. 提交于 2021-01-27 17:28:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!