Make @chain base Julia

Instead of having the @chain macro, how about making the previous line’s output always available (if you want it) through “_” or by omitting the first argument of a function.
So you could write something like.


julia> 15


@rtransform :B = :A + 1
@with :B

julia> 20

If you need to break a given chain you could just store the current value to a global variable X=_ then use it to resume at any point.
→ X might also be a nice shorthand for X= _

A single . on a line could mean the following line or block operates on an element-wise level like .|> so variables defined within the block would not have global scope.
The above example could be written

    A = _
    B = A + 1

This could remove the need for both the @chain and @pipe macros
Rather than something |> something |> something
you would write something ; something ; something

I find 90% of my code is within @chain blocks. It would save a lot of code to have the functionality by default.

1 Like

I think there’s definitely room for a custom REPL mode that makes this easy.

1 Like

“Previous output as the first argument of a function” goes somewhat against the common julia argument order, Style Guide · The Julia Language. If anything, the default rule should be “the argument that follows all callable arguments”: this works for all common functions like map/filter in Base, and a wide range of packages.
Btw, this is close to the rule followed by another (my) piping package DataPipes.jl - it puts the previous output as the last argument.

This discussion has been had many times, and the conclusion has always been that there’s enough reasonable disagreement of what the “standard” way of doing this should be that it shouldn’t be in base.

This is evidenced by a number of useful and actively developed packages that provide similar functionality, and also by the first few answers in this thread…