我正在尝试编写一个方案解析器作为练习,但我不确定如何实现向量语法。 specification似乎表明输入向量的方式是 '#(1 2 3)
并且这样的向量应该计算为 #(1 2 3)
。然而,当我尝试几个Scheme实现时,#(1 2 3)
也被接受为有效输入。这是规范的普遍实现的扩展吗?
最佳答案
根据 R5RS 规范,向量必须加引号:
Note that this is the external representation of a vector, not an expression evaluating to a vector. Like list constants, vector constants must be quoted:
'#(0 (2 2 2 2) "Anna")
某些实现选择允许评估未加引号的向量,但任何此类扩展都是非标准的,并且是该特定实现的“功能”。
无论怎样,即将推出的R7RS spec明确要求向量进行 self 评估:
Vector constants are self-evaluating, so they do not need to be quoted in programs.
关于parsing - R5RS 方案中未加引号的向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18641757/