关于 Scheme 的缺点和点符号 [英] On Scheme cons and dots notation

查看:72
本文介绍了关于 Scheme 的缺点和点符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定

#;> (cons (cons 1 2) 3)
((1 . 2) . 3)

当我们尝试

#;> (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)

在您的示例中,如果不是最后一个 2(cons 3 (cons 1 2)) 将是一个列表.因此,您的实现会尽最大努力将其打印为列表,直到 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.

这篇关于关于 Scheme 的缺点和点符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆