I'm trying to grok macros, and I'm using html templating as my playground. So I defined a function "tag" so that: (tag "div" "Hey")
return: "<div>Hey</div>"
Then I made a macro `def-tag` so that:(def-tag div) defines a function `div` so I can say (div "Hey") And get the same output as above Now I'm basically at the point where I can write: (def-tag div)
(def-tag span)
(def-tag p) ... etc And this seems to be working so far. But now I'm trying to take it a step further: I want to define all these tags in one step without repeating the def-tag command. As in: (def-tags div p span html title body head) You see where I'm going? So I tried: (each name '(html title head body div span p h1 h2 h3 h4 i em strong b)
(def-tag name))
But it's not working; it simply doesn't define anything!I'm obviously doing something wrong. Putting some debug statements inside my 'def-tag' macro reveals that I'm basically passing "name" as the symbol to def-tag, which defines a name tag, not what name is referring to. I don't want to pass the symbol name, I want to pass the symbol that name is supposed to be referring to from that 'each' block. Also, the definition becomes local inside that 'each' block and is not accessible from outside, so even I manage to get that names vs symbols thing right, the definition will stay local. Help? |