Common lisp 使readmacros UCI Lisp代码适应公共Lisp
我正在尝试将公共lisp等效于模式匹配的UCI lisp/Interlisp辅助函数Common lisp 使readmacros UCI Lisp代码适应公共Lisp,common-lisp,clisp,Common Lisp,Clisp,我正在尝试将公共lisp等效于模式匹配的UCI lisp/Interlisp辅助函数 (DRM /? (LAMBDA () (LIST '*VAR* (READ] 文件如下: -Variables, which are used by the pattern matcher, start with a question mark ("?"), as in ?FOO. -This is converted internally to (*VAR* role-name), so ?FOO beco
(DRM /? (LAMBDA () (LIST '*VAR* (READ]
文件如下:
-Variables, which are used by the pattern matcher, start with a question mark ("?"), as in ?FOO.
-This is converted internally to (*VAR* role-name), so ?FOO becomes (*VAR* FOO).
-The DRM defines ? to convert itself to *VAR* when it is read
这是我目前对it的实施:
(set-macro-character #\? (lambda () (list '*var* (read))))
但当我运行下面的匹配函数时:
(match (ptrans (actor ?x) (object ?x) (to (store)))
(ptrans (actor (person)) (object (person)) (to (store))) nil)
我从DRM函数中得到以下错误:
*** - EVAL/APPLY: too many arguments given to :LAMBDA
我的实现正确吗?读卡器宏函数需要接受两个参数:一个用于读取源代码的流,另一个用于触发调用它们的字符。如果将实现更改为
(set-macro-character #\? (lambda (stream char)
(declare (ignore char))
(list '*var* (read stream))))
然后任何出现的?x
将被读取为(*VAR*x)
。
请注意,如果用作函数参数,将对其进行计算,如果VAR不是绑定函数/宏,则会导致错误
您可能希望将?x
读入为”(*VAR*x)
(请注意引号)以获取作为数据的列表。
在这种情况下,您应该执行以下操作:
(set-macro-character #\? (lambda (stream char)
(declare (ignore char))
(list 'quote
(list '*var* (read stream)))))
为了防止对读取器宏函数返回的表单进行求值。读取器宏函数需要接受两个参数:一个用于读取源代码的流,另一个用于触发调用它们的字符。如果将实现更改为
(set-macro-character #\? (lambda (stream char)
(declare (ignore char))
(list '*var* (read stream))))
然后任何出现的?x
将被读取为(*VAR*x)
。
请注意,如果用作函数参数,将对其进行计算,如果VAR不是绑定函数/宏,则会导致错误
您可能希望将?x
读入为”(*VAR*x)
(请注意引号)以获取作为数据的列表。
在这种情况下,您应该执行以下操作:
(set-macro-character #\? (lambda (stream char)
(declare (ignore char))
(list 'quote
(list '*var* (read stream)))))
为防止对读取器宏函数返回的表单求值。函数应接受两个参数,但与宏字符关联的lambda不接受任何参数:有关详细信息和示例,请参阅函数应接受两个参数,但与宏字符关联的lambda不接受任何参数:有关详细信息和示例,请参阅