我是Scheme编程的初学者.我知道Scheme中的点符号用于表示一对符号,例如'(a . b)
.
第一个元素可以是符号,也可以是列表,无关紧要.但特别是第二个元素必须是一个符号,如果不是,可能是一个列表,那么我们就不能创建一个内置cons
过程的对.
那么有可能创建一对2列表??? 好吧,我正在考虑一个解决方案是将列表转换为符号,但实际上这些是完全不同的两件事 - >根据我的理解不可能.
这是我写的代码:
(define compare-attrs
(lambda (attribute1 attribute2)
(if (or (and (null? attribute1) (null? attribute2)) (and (not (null? attribute1)) (not (null? attribute2))))
(cons attribute1 attribute2)
#f)))
Run Code Online (Sandbox Code Playgroud)
其中attribute1和attribute2是2个列表,我的输出是:
attribute1 atrribute2
Run Code Online (Sandbox Code Playgroud)
预期输出:'(attribute1.attribute2)
请解释一下.预先感谢!!!
编辑:添加比较attrs功能的使用
函数compare-attrs用于提取描述实体属性的部分,并将cons
它们组成一对,实体定义如下:
(entity e0 (prov:label "entity e0")
(entity e1 (prov:location "London")
Run Code Online (Sandbox Code Playgroud)
所以这些实体的属性是(prov:label "entity e0")
和(prov:location "London")
.当应用函数compare-attrs时,因为这些属性不是null
,所以我期望的输出是
`(prov:label "entity e0") . (prov:location "London")`
Run Code Online (Sandbox Code Playgroud) scheme ×1