2010-01-11 65 views
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中創建這種類似的東西的過程嗎?PLT方案:在「鑄造SPELs在LISP」

回答

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 - 看到郵件列表上的post

+0

非常感謝!^_ ^ – 2010-01-12 04:16:04