Here's what I've ended up with: https://gist.github.com/abe-egnor/5886315f61b5d9ae5ba5 It provides nice enum-type semantics: method dispatch and a convenience ALL constant for iterating over the values.
It seems that doing eval() to build up module state is a bit more reliable at the moment than trying to build the entire AST of the desired result in one go. On Sat Jul 12 2014 at 12:13:47 PM, Abraham Egnor <[email protected]> wrote: > Addendum the second - the version I'm using is: > > Version 0.3.0-prerelease+3921 (2014-06-28 02:01 UTC) > Commit 0b46af5* (14 days old master) > x86_64-linux-gnu > > > On Sat Jul 12 2014 at 10:21:10 AM, Abraham Egnor <[email protected]> > wrote: > >> Mistake copy-pasting to the gist: the final line should read >> >> eval(enum_f(:Rotation, :CW, :CCW)) >> >> On Sat Jul 12 2014 at 10:19:21 AM, Abraham Egnor <[email protected]> >> wrote: >> >>> Gist is here: https://gist.github.com/abe-egnor/7b1fadfe2197512ab91b >>> >>> I'm very unexperienced with macros, so I can't tell if I'm doing things >>> wrong or bumping into bugs. When attempting to make a simple macro to >>> capture a particular pattern for implementing an enum type, I ran into >>> multiple issues: >>> >>> A - it looks like, when quoting a baremodule with a spliced name, the >>> module parsing binds to the $ as the name of the module, and you're left >>> with a raw variable name in the module body. >>> B - I couldn't find a way to directly splice in an expression list >>> C - macro expansion is barfing ("malformed module expression") on exprs >>> that work just fine when eval()'d. >>> >>> Would much appreciate guidance on whether I should update my code or >>> file bugs :) >>> >>
