Re: [julia-users] creation of parametric variables in a macro

2015-03-07 Thread Abe Schneider
Awesome, thanks for the suggestions. I ended up independently implementing your second solution, which I think is the more elegant way to do it. But it's good to know about the first approach as well. For anyone who is interested, here's the code I ended up with: # general case, just return val

Re: [julia-users] creation of parametric variables in a macro

2015-03-06 Thread Jameson Nash
oh, that’s reasonably easy then: macro testfn(expr) children = esc(:children) syms = [:($(symbol(string("_", i))) = $children[$i]) for i = 1:10] return Expr(:let, Expr(:block, esc(expr)), :(children=children), syms..) end which will expand to: let children=children, _1 = children[1],

Re: [julia-users] creation of parametric variables in a macro

2015-03-06 Thread Abe Schneider
Hmmm, good to know. Thank you. The rationale for doing so is to provide a shortcut for the elements of a variable `children`. Specifically, for a grammar, I might have a rule like: ``` @grammar foo begin number = r"[0-9]+" { parseint(children[1]) } end ``` What I would like to have instead,

Re: [julia-users] creation of parametric variables in a macro

2015-03-06 Thread Jameson Nash
you can't do what you are proposing, by design. a macro cannot do anything that you cannot express directly, it simply allows you to express it more succinctly by templating the redundant parts. if you want a "set" or "numbered list", use a set or number list. variables are bad at that sort of tas

[julia-users] creation of parametric variables in a macro

2015-03-06 Thread Abe Schneider
I'm trying to create a set of variables (_1, _2, ...) from items within a list in a macro. I have a (much) condensed version of the code: macro testfn() quote i = 1 value = [1, 2, 3] $(Expr(:(=), Expr(:symbol, Expr(:string, "_", :i)), :value)) println(_1) e