Lisp - 无论如何要转换“(”到符号'(

时间:2015-03-04 04:23:02

标签: lisp

有没有转换字符串括号"("到符号括号'(在lisp中?) 例如,将字符串列表转换为符号列表时;
("("")")=> (())

2 个答案:

答案 0 :(得分:7)

"("字符可以输入为#\(

如果您想要一个打印名称为"("您可以使用竖线输入它的符号:

'|(|

或者如果你有一个字符串列表,其中每个字符串都是"(",你可以使用intern将每个字符串转换为符号:

(intern "(") => |(|

答案 1 :(得分:2)

你可以使用escape,就像这样:

* (list '\( '\) 123)
(|(| |)| 123)

根据Common Lisp阅读器算法的规则之一(取自CLTL2):

5. If x is a single escape character (normally \), then read the next 
character and call it y (but if at end of file, signal an error 
instead). Ignore the usual syntax of y and pretend it is a 
constituent whose only attribute is alphabetic.