views:

48

answers:

1
    (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.)))))

Thats the code from http://www.lisperati.com/actions.html for the 'macro defining macro'. I can't seem to convert it appropriately to scheme. Can someone explain to me the process of creating this same sort of thing in Scheme?

+3  A: 

This kind of macro is actually much simpler in Scheme, since you can do it all with define-syntax-rule (in standard Scheme code you will need define-syntax + syntax-rules). You basically do the same thing, minus the whole quote/unquote mess.

(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.)])))

And since this is actually most of the code, I ported the whole thing to PLT -- see the post on the mailing list.

Eli Barzilay
Thank you very much! ^_^
Timothy McDowell