You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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)()
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.
Here is an edge case I think is worth looking into
The text was updated successfully, but these errors were encountered: