jkrumbiegel / Chain.jl

A Julia package for piping a value through a series of transformation expressions using a more convenient syntax than Julia's native piping functionality.
MIT License
368 stars 16 forks source link

Do we really need `begin` and `end` in the expression? #17

Closed pdeffebach closed 3 years ago

pdeffebach commented 3 years ago

In Lazy's @> you can do

@> rand(2, 3) DataFrame(:auto)

But in Chain you need

julia> @chain rand(2, 3) DataFrame(:auto)
ERROR: LoadError: Second argument of @chain must be a begin / end block
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] rewrite_chain_block(::Expr, ::Expr) at /home/peterwd/.julia/packages/Chain/HuSPl/src/Chain.jl:66
 [3] @chain(::LineNumberNode, ::Module, ::Any, ::Expr) at /home/peterwd/.julia/packages/Chain/HuSPl/src/Chain.jl:113
in expression starting at REPL[22]:1

Is there a technical reason for this? Maybe it's not necessary?

jkrumbiegel commented 3 years ago

It's not "technical" as much as I just didn't implement that syntax because I assumed data wrangling would never happen on a single line, if a chaining macro is used already to reduce the complexity. But maybe I'm wrong :) we could easily add this, someone else already made an issue about this earlier

adkabo commented 3 years ago
@chain begin
    1
    -
end

and

@chain 1 begin
    -
end

Seems like the begin might not be doing much here. Is there a case where the begin can't just be inferred automatically?

jkrumbiegel commented 3 years ago

Those two syntax alternatives are both explicitly implemented. The begin block is necessary to bundle the expressions on different lines. You can't do that with parentheses alone, that doesn't parse.

pdeffebach commented 3 years ago

Closed in #24