Skip to content

Pattern closures not supported #2

@MasonProtter

Description

@MasonProtter

Currently, pattern functions are generated functions so the following happens:

julia> using PatternDispatch

julia> @pattern f(x) = y -> y + x
f (generic function with 2 methods)

julia> f(1)
ERROR: The function body AST defined by this @generated function is not pure. This likely means it contains a closure or comprehension.
Stacktrace:
 [1] f(::Int64) at /Users/mason/Documents/Julia/PatternDispatch/src/PatternDispatch.jl:46
 [2] top-level scope at REPL[3]:1

I've tried switching to using @gg from GeneralizedGenerated.jl but get some errors I haven't had time to figure out:

julia> using PatternDispatch

julia> @pattern f(x) = y -> y + x
f (generic function with 2 methods)

julia> f(1)
ERROR: MethodError: Cannot `convert` an object of type Expr to an object of type Symbol
Closest candidates are:
  convert(::Type{T}, ::T) where T at essentials.jl:168
  Symbol(::Any...) at strings/basic.jl:206
Stacktrace:
 [1] GeneralizedGenerated.NGG.Argument(::Expr, ::Nothing, ::GeneralizedGenerated.NGG.Unset) at /Users/mason/.julia/packages/GeneralizedGenerated/NDqgV/src/ngg/runtime_fns.jl:19
 [2] of_args(::Array{GeneralizedGenerated.FuncArg,1}) at /Users/mason/.julia/packages/GeneralizedGenerated/NDqgV/src/func_arg_decs.jl:61
 [3] ##GeneralizedGenerated 237#707#59 at /Users/mason/.julia/packages/GeneralizedGenerated/NDqgV/src/closure_conv.jl:45 [inlined]
 [4] ##GeneralizedGenerated 235#705#58 at ./none:0 [inlined]
 [5] ##GeneralizedGenerated 228#698#57 at ./none:0 [inlined]
 [6] ##GeneralizedGenerated 226#696#56 at ./none:0 [inlined]
 [7] (::GeneralizedGenerated.var"#conv#53"{Module})(::Expr) at /Users/mason/.julia/packages/GeneralizedGenerated/NDqgV/src/closure_conv.jl:27
 [8] closure_conv(::Module, ::Expr) at /Users/mason/.julia/packages/GeneralizedGenerated/NDqgV/src/closure_conv.jl:78
 [9] #s21#8(::Any, ::Any, ::Any) at /Users/mason/.julia/packages/GeneralizedGenerated/NDqgV/src/closure_conv.jl:121
 [10] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:524
 [11] f(::Int64) at /Users/mason/Documents/Julia/PatternDispatch/src/PatternDispatch.jl:46
 [12] top-level scope at REPL[3]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions