Hi all,
I was playing around with an idea for a code generator for a language we'll call "platypus" by defining an s-expression syntax for it, something like c-amplify
I defined (in the "platypus" package) some expansion macros with names like "class" and "function" that happen to be symbols in CL. For convenience, I'd like the user to be able to use these tokens "unadorned" by introducing the new syntax by wrapping it in a form like so:
Then next best I could do was:
Is there a better approach to this? Am I looking at the problem in the wrong way?
I was playing around with an idea for a code generator for a language we'll call "platypus" by defining an s-expression syntax for it, something like c-amplify
I defined (in the "platypus" package) some expansion macros with names like "class" and "function" that happen to be symbols in CL. For convenience, I'd like the user to be able to use these tokens "unadorned" by introducing the new syntax by wrapping it in a form like so:
(platypus
;; Introduces new syntax & symbol table
(class blah ...
... etc... ))
I thought I could make this happen by lexically binding *package* like this:(defmacro platypus (&body body)
`(let ((*package* (find-package :platypus)))
,@body))
But this doesn't seem to work with the binding either inside or outside the quasi-quote. I presume this is because the reader has already snarfed all the tokens for the whole form by the time we macroexpand?Then next best I could do was:
(defmacro platypus (&body body)
`(macrolet ((class (&body body)
`(platypus:class ,@body)))
,@body))
This seems to work, at least for trivial uses, which is probably good enough for now, but it seems a little clunky.Is there a better approach to this? Am I looking at the problem in the wrong way?
Last edited by garethw on , edited 1 time in total.
~garethw