On Wed, Feb 12, 2014 at 12:01 AM, Tim Holy <[email protected]> wrote:

> On Tuesday, February 11, 2014 02:29:54 PM Fil Mackay wrote:
> > OK - would this be a valuable tool to have around? Or does it reduce to
> > something simpler that I'm not aware of?
>
> Since Base.Cartesian already exists, I guess the extra thing this gives
> you is
> the ability to start at something higher than 1. Truth be told, you can do
> that with @nexprs too; I'll leave it as an exercise in reading Cartesian's
> documentation :).
>

I am actually thinking of a much wider context - creating from other
arbitrary iterable data structures. ie. more complex than ranges. Think of
compiling from a DSL etc. - in my current case it's some JSON.

I ended up settling on something pretty manual, but it works. Very
impressed with expressions in general, the only wrinkle was that I wish
that the symbol operator (:) was different from the quote (:) to avoid
ambiguity.

For completeness, this is what I ended up using to generate by dynamic type:

    @eval type $(symbol(name)) <: $(if root Root else Other end)
        $(Expr(:block, [tsymbol(n, :(Parent{$(d.datatype)})) for (n,d) in
parent.columns]...))
        $(Expr(:block, [tsymbol(n, :Child) for (n,d) in
parent.children]...))

        # other fields
        idx::Uint32
        file::IOStream

        # conditional fields
        $(if root
            :(begin
                path::String
            end)
        else
            :(begin
                parent::Parent
            end)
        end)
    end

Reply via email to