(defspel game-action (command subj obj place &rest rest)
`(defspel ,command (subject object)
`(cond ((and (eq *location* ',',place)
(eq ',subject ',',subj)
(eq ',object ',',obj)
(have ',',subj))
,@',rest)
(t '(i cant ,',command like that.)))))
这是来自 http://www.lisperati.com/actions.html 的代码对于“宏定义宏”。我似乎无法将其适本地转换为方案。有人可以向我解释一下在Scheme中创建同样的东西的过程吗?
最佳答案
这种宏在Scheme中实际上要简单得多,因为您可以使用define-syntax-rule
来完成这一切(在标准Scheme代码中,您将需要define-syntax
> + 语法规则
)。你基本上做同样的事情,减去整个引用/取消引用的困惑。
(defspel (game-action command subj obj place rest ...)
(defspel (command subject object)
(cond [(and (eq? *location* 'place)
(eq? 'subject 'subj)
(eq? 'object 'obj)
(have 'subj))
rest ...]
[else '(i cant command like that.)])))
由于这实际上是大部分代码,因此我将整个代码移植到了 PLT - 请参阅 post在邮件列表中。
关于scheme - PLT方案: Converting one of the macros in 'Casting SPELs in LISP' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2045796/