Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd behavior with anonymous functions #20

Closed
pdeffebach opened this issue Mar 7, 2021 · 3 comments
Closed

Odd behavior with anonymous functions #20

pdeffebach opened this issue Mar 7, 2021 · 3 comments

Comments

@pdeffebach
Copy link
Contributor

Here is an edge case I think is worth looking into

julia> using Chain

julia> x = 1
1

julia> @chain x begin 
       (t -> t + 1)
       end
ERROR: LoadError: Can't prepend first arg to expression t->begin
        #= REPL[76]:2 =#
        t + 1
    end that isn't a call.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] insert_first_arg(::Expr, ::Symbol) at /home/peterwd/.julia/packages/Chain/HuSPl/src/Chain.jl:38
 [3] rewrite(::Expr, ::Symbol) at /home/peterwd/.julia/packages/Chain/HuSPl/src/Chain.jl:53
 [4] rewrite_chain_block(::Symbol, ::Expr) at /home/peterwd/.julia/packages/Chain/HuSPl/src/Chain.jl:80
 [5] @chain(::LineNumberNode, ::Module, ::Any, ::Expr) at /home/peterwd/.julia/packages/Chain/HuSPl/src/Chain.jl:113
in expression starting at REPL[76]:1

julia> @chain x begin 
       (t -> t + 1)(_)
       end
2
@jkrumbiegel
Copy link
Owner

Well the readme says there's only implicit function calling for symbols. Here you have a whole expression which, granted, is evaluated to a function. First-argument splicing only works for function calls and macros, not for arbitrary expressions. Also, why are you doing this if _ + 1 works?

And what should work I guess is making the function call explicit: (t -> t + 1)()

@pdeffebach
Copy link
Contributor Author

That sounds good!

This is fine, i will close.

@jkrumbiegel
Copy link
Owner

Part of this is that the weirder the expressions that I allow in the macro, the harder it becomes to read, potentially. I think a single symbol is very easy to parse as a supposed function call, but your example would already be too close optically to an expression in which an underscore could hide somewhere, making it a different thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants