This isn't something that you would do using symbol-macros, but rather with macro characters. You can set macro characters using the aptly named set-macro-character. For instance, in the following, I set the macro character for % to be a function that reads a list, using read-delimited-list that should be terminated by ^. (Using the characters a and b here will prove very difficult, because you won't be able to write things like (set-macro-character ...) afterwards; it would be like writing (set-m(cro-ch(r(cter ...), which is not good.)CL-USER> (set-macro-character #\% (lambda (stream ignore) (declare (ignore ignore)) (read-delimited-list #\^ stream)))TCL-USER> % + 1 1 ^2相关的set-syntax-from-char 这里有一个相关的功能几乎可以满足您的需求, set-syntax-from-char .您可以使用它使一个角色表现得与另一个角色相同.例如,您可以使%的行为类似于( The related set-syntax-from-charThere's a related function that almost does what you want here, set-syntax-from-char. You can use it to make one character behave like another. For instance, you can make % behave like (CL-USER> (set-syntax-from-char #\% #\()TCL-USER> % + 1 1 )2但是,由于与(关联的宏字符不是在寻找与)语法相同的字符,而是 actual )字符,因此您不能只需用相同的方式将)替换为^:However, since the macro character associated with ( isn't looking for a character that has the same syntax as ), but an actual ) character, you can't simply replace ) with ^ in the same way:CL-USER> (set-syntax-from-char #\^ #\))TCL-USER> % + 1 1 ^; Evaluation aborted on #<SB-INT:SIMPLE-READER-ERROR "unmatched close parenthesis" {1002C66031}>.当现有角色本身要模仿时, set-syntax-from-char会更有用.例如,如果您想为!附加一个引号字符:set-syntax-from-char is more useful when there's an existing character that, by itself does something that you want to imitate. For instance, if you wanted to make ! an additional quotation character:CL-USER> (set-syntax-from-char #\! #\')TCL-USER> (list !a !(1 2 3))(A (1 2 3))或将%用作注释字符,就像在LaTeX中一样:or make % be a comment character, like it is in LaTeX:CL-USER> (set-syntax-from-char #\% #\;)TCL-USER> (list 1 2 % 3 4 5 6)(1 2 5 6)但是考虑一下为什么要这么做……现在,即使您可以完成所有这些工作,对于任何碰到它的人来说,这似乎都是完全令人惊讶的. (也许您正在参加一个混乱的编码竞赛?;).由于上面显示的原因,使用a和b这样的常用字符进行此操作也将使编写更多的源代码变得非常困难.最好定义一个完全可以执行您想要的操作的全新readtable,甚至编写一个新的解析器.即使(通用)Lisp lets 您重新定义了语言,但仍有一些事情可能会让您保持孤独.But consider why you're doing this at all…Now, even though you can do all of this, it seems like something that would be utterly surprising to anyone who ran into it. (Perhaps you're entering an obfuscated coding competition? ;)) For the reasons shown above, doing this with commonly used characters such as a and b will also make it very difficult to write any more source code. It's probably a better bet to define an entirely new readtable that does what you want, or even write a new parser. even though (Common) Lisp lets you redefine the language, there are still things that it probably makes sense to leave alone. 这篇关于如何通过符号宏定义将像(和)一样工作的符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-01 16:51