Gray,

You can make parametric types that depend on symbols. Read the code in 
Calculus.jl for examples: 
https://github.com/johnmyleswhite/Calculus.jl/blob/master/src/symbolic.jl

 -- John

On Sep 10, 2014, at 9:20 AM, Gray Calhoun <[email protected]> wrote:

> Hi everyone, I'm writing code using expressions fairly heavily (mainly as a 
> learning exercise), and am using lots of constructions like:
> 
> function haskey(df::MyDataType, key::Expr)
>     key.head == :call  && return(all([haskey(df, x) for x in 
> key.args[2:end]]))
>     key.head == :(=)   && return(haskey(df, key.args[2]))
>     key.head == :block && return(all([haskey(df, x) for x in key.args]))
>     key.head == :line  && return(true)
>     warn("Didn't expect to get here...")
>     false
> end
> 
> Some quick questions:
> 
> 1) Is there a way of mimicking Expr subtypes that I'm not aware of that would 
> let me rewrite this as several different methods? Are there better ways to do 
> this in general?
> 
> 2) Is there a list anywhere of the different possible values for Expr.head? 
> (I don't see it in the metaprogramming section of the manual, but may have 
> missed it.)
> 
> 3) How much of Julia would it break or slow down to make Expr an abstract 
> type with the contents of "head" implemented as different subtypes? (This 
> last one is mostly just asked out of curiosity.)
> 
> Thanks!

Reply via email to