PatternDispatch.jl icon indicating copy to clipboard operation
PatternDispatch.jl copied to clipboard

Add switch statement

Open toivoh opened this issue 12 years ago • 1 comments

Possible syntax:

@match expression begin
    (x::Int)->print(x)
    1->print("one")
    x->print("Not an Int")
end

This should probably create a decision tree directly, without using cooperative dispatch?

toivoh avatar Dec 25 '12 05:12 toivoh

Need to figure out the steps to compile this sort of thing. With @pattern function, we can generate code with the method definition to evaluate the pattern and body function, then create dispatch code using eval. That is possible since @pattern is invoked at the point of definition, not use.

Is it possible to create dispatch code that knows about the local context, without recompiling at each invocation? Pattern evaluation is currently mostly used to translate symbols to types in type assertions. Could we create a staged method for the switch dispatch based on what they evaluate to?

toivoh avatar Dec 25 '12 09:12 toivoh