On Wed, Oct 15, 2008 at 10:02 PM, Tom Lynch <[EMAIL PROTECTED]> wrote: > > Hi all, I have a naive question regarding Clojure macros. As someone > new to Lisp-style macros, can I use the system to generate new names > using substitution / token-pasting? [snip]
> I realise this may be a huge ideological no-no :-) Well, you'd better have a darn good reason to not be using namespaces or a hash-map or something. :-) But sure, it's possible: user=> (defmacro paste-tokens [first second] `(def ~(symbol (str first second)) [])) nil user=> (macroexpand '(paste-tokens foo bar)) (def foobar []) The thing to realize is that your macro is just returning a data structure, and of course you can return a data structure that includes computed symbol names. Another way to write the above macro may help defuse some of the magic quoting magic: (defmacro paste-tokens [first second] (list 'def (symbol (str first second)) [])) --Chouser --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---