-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make functions print as valid julia expressions.
Previously, function instances would be printed in `static_show()` as elements of a `DataType`, with no special printing for `<:Function`s. This led to printing them via _invalid_ syntax, since there is no empty constructor for `T<:Function`. Before: ```julia julia> g() = 2 g (generic function with 1 method) julia> println(static_shown(g)) typeof(Main.g)() julia> eval(Meta.parse(static_shown(g))) ERROR: MethodError: no method matching typeof(g)() ``` After: ```julia julia> g() = 2 g (generic function with 1 method) julia> println(static_shown(g)) Main.g julia> eval(Meta.parse(static_shown(g))) g (generic function with 1 method) ``` I chose to keep the Module prefix on the functions, so that they will be valid julia expressions that you can enter at the REPL to reproduce the function instance, even though this is a break from the julia `show()` behavior. One caveat is that this is still not correct for anonymous functions, but I'm also not really sure what would be a better way to print anonymous functions... I think this is _probably_ better than it was before, but very open to suggestions for how to improve it. Before: ```julia julia> l = (x,y)->x+y julia> println(static_shown(l)) getfield(Main, Symbol("#3#4"))() julia> eval(Meta.parse(static_shown(l))) ERROR: MethodError: no method matching var"#3#4"() ``` After: ```julia julia> l = (x,y)->x+y julia> println(static_shown(l)) Main.var"#3" julia> eval(Meta.parse(static_shown(l))) ERROR: UndefVarError: #3 not defined ```
- Loading branch information
Showing
3 changed files
with
55 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters