问题描述
SICP Section 2.2.2 (Hierarchical Structures)的第二句话:作者说curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
(由三个元素组成的列表)可以由helm version
构成。
我认为(当然是错误的)它会构造((1 2) 3 4)
(两个元素),原因是:
-
(cons (list 1 2) (list 3 4))
和((1 2) (3 4))
将被封装在嵌套的3
中,而不是顶层4
中,并且 -
list
构造一对项目,而对意味着2个元素而不是3个。
我在这里看不懂什么?
解决方法
列表是成对的链,以一对namespace Kunden2
{
public class Customer
{
[XmlAttribute]
public bool Aktiv { get; set; }
[XmlAttribute]
public int KundenNummer { get; set; }
[XmlElement]
public string Name { get; set; }
public string NachName { get; set; }
public string Firma { get; set; }
}
}
为空列表的对结束。
cdr
是两对,等效于
(list 3 4)
所以 (cons 3 (cons 4 '()))
是3对,等于
(cons (list 1 2) (list 3 4))
通常,如果您有一个列表(cons (list 1 2) (cons 3 (cons 4 '())))
,则可以使用以下命令创建一个新列表,该列表的前面带有一个新元素:
old-list
如果你写的话,你会得到预期的结果
(cons new-element old-list)