OK - would this be a valuable tool to have around? Or does it reduce to something simpler that I'm not aware of?
The idea of replacing the "i" in the anonymous function seems a bit creepy..? function _itexprs(it) Expr(:escape, Expr(:block, eval(it)...)) end macro itexprs(it) _itexprs(it) end @eval begin type Test0 @itexprs [symbol("a_$i") for i in 3:5] end end names(Test0) 3-element Array{Symbol,1}: :a_3 :a_4 :a_5 On Tue, Feb 11, 2014 at 2:24 PM, Tim Holy <tim.h...@gmail.com> wrote: > Yes, that's fine. I thought you meant in combination with generating > multiple > types of different names. > > --Tim > > On Tuesday, February 11, 2014 01:57:08 PM Fil Mackay wrote: > > I just implemented an "itexprs" and it gives: > > > > @eval begin > > type Test1 > > @itexprs 3:5 i->a_i::Int > > end > > end > > > > names(Test1) > > > > 5-element Array{Symbol,1}: > > :a_3 > > :a_4 > > :a_5 > > > > Is this not useful, in that I can now pass in any iterator not just a > 1:N.. > > doesn't the above allow you to avoid collisions? > > > > On Tue, Feb 11, 2014 at 1:42 PM, Tim Holy <tim.h...@gmail.com> wrote: > > > On Monday, February 10, 2014 06:19:03 PM Fil Mackay wrote: > > > > Nice one.. is there a @nexprs that can take a compile-time iterable, > and > > > > map function that produces a child expression for each item? Kind of > > > > like > > > > replacing $N with "1:5" rather than one value at a time. That's what > I'm > > > > really looking for. > > > > > > No there isn't, and at the moment I don't see how it would be useful. > In > > > many > > > circumstances you use a whole collection of cartesian macros together, > and > > > guessing how the different terms are supposed to be interleaved would > be > > > an > > > exercise in mind-reading. For example, in this case, if @nexprs took a > > > 1:5, > > > you'd be trying to generate multiple fields named a_1 within a single > > > type, > > > which would obviously be an error. > > > > > > --Tim >