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
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],
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,
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
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