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..
On Monday, February 10, 2014 11:42:31 PM UTC+11, Tim Holy wrote: > > On Monday, February 10, 2014 03:16:18 AM Fil Mackay wrote: > > Is there an equivalent that allows a for loop iterator to construct the > > type.. Base.Cartesian.@forexprs perhaps? :) > > Base.Cartesian is a slightly-enhanced version of the original Cartesian.jl > package; the README there is (in my personal opinion) quite thorough. The > version in base is intentionally undocumented since we don't plan on > exporting > it. > > But I'm wondering if perhaps you're simply wondering if you can replace > "5" in > my example with something else. The answer is yes: > > julia> for N = 1:5 > typename = symbol(string("MyType", N)) > @eval begin > type $typename > Base.Cartesian.@nexprs $N i->a_i::Int > end > end > end > > julia> MyType2.names > (:a_1,:a_2) > > julia> MyType4.names > (:a_1,:a_2,:a_3,:a_4) > >