# Make @chain base Julia

**URL:** <https://discourse.julialang.org/t/make-chain-base-julia/71357>\
**Category:** General Usage\
**Tags:** macros, suggestions\
**Created:** [November 12, 2021, 12:52am UTC](https://discourse.julialang.org/t/make-chain-base-julia/71357 "2021-11-12T00:52:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Post date:** [November 12, 2021, 12:52am UTC](https://discourse.julialang.org/t/make-chain-base-julia/71357/1 "2021-11-12T00:52:23Z")

</div>

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
1:5
sum

```

julia\> `15`

or

```julia
1:5
DataFrame(A=_)
@rtransform :B = :A + 1
@with :B
sum

```

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

```julia
1:5
.
begin
    A = _
    B = A + 1
end
sum

```

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.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 12, 2021, 1:17am UTC](https://discourse.julialang.org/t/make-chain-base-julia/71357/2 "2021-11-12T01:17:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [November 12, 2021, 5:45am UTC](https://discourse.julialang.org/t/make-chain-base-julia/71357/3 "2021-11-12T05:45:35Z")

</div>

> [@Lincoln\_Hannah](#):
>
> how about making the previous line’s output always available (if you want it) through “\_” or by omitting the first argument of a function.

“Previous output as the first argument of a function” goes somewhat against the common julia argument order, [Style Guide · The Julia Language](https://docs.julialang.org/en/v1/manual/style-guide/#Write-functions-with-argument-ordering-similar-to-Julia-Base). 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](https://juliahub.com/ui/Packages/DataPipes/jwfGJ) - it puts the previous output as the last argument.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [November 12, 2021, 6:30am UTC](https://discourse.julialang.org/t/make-chain-base-julia/71357/4 "2021-11-12T06:30:51Z")

</div>

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…
