Skip to content

Cannot interpolate a function into a method declaration. #47726

@LilithHafner

Description

@LilithHafner

It's possible to embed a function (not a symbol that represents the function) in an expression and execute it. It seems like it should also be possible to embed a function in an expression and define a new method for it.

julia> f() = 1
f (generic function with 1 method)

julia> eval(:($f()))
1

julia> eval(:(f() = 2))
f (generic function with 1 method)

julia> f()
2

julia> eval(:($f() = 3))
ERROR: syntax: invalid function name "Main.f" # Actual
f (generic function with 1 method)            # Desired

julia> f()
2 # Actual
3 # Desired

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions