2
    (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 中创建同样类型的东西的过程吗?

4

1 回答 1

4

这种宏在Scheme中实际上要简单得多,因为您可以使用define-syntax-rule(在标准Scheme代码中您需要define-syntax+ syntax-rules)来完成这一切。你基本上做同样的事情,减去整个引用/取消引用的混乱。

(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——请参阅邮件列表上的帖子。

于 2010-01-12T02:53:24.940 回答