# RFC: \_ as ans

**URL:** <https://discourse.julialang.org/t/rfc---as-ans/2326>\
**Category:** Internals & Design\
**Created:** [February 27, 2017, 1:06am UTC](https://discourse.julialang.org/t/rfc---as-ans/2326 "2017-02-27T01:06:29Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [February 28, 2017, 3:02pm UTC](https://discourse.julialang.org/t/rfc---as-ans/2326/21 "2017-02-28T15:02:22Z")

</div>

The biggest difference between this and %\>% is that %\>% additionally automatically inserts to the first argument, which is quite useful in R, but not in Julia, which uses different argument order conventions.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 28, 2017, 3:09pm UTC](https://discourse.julialang.org/t/rfc---as-ans/2326/22 "2017-02-28T15:09:06Z")

</div>

> [@bramtayl](#):
>
> The biggest difference between this and %\>% is that %\>% additionally automatically inserts to the first argument, which is quite useful in R, but not in Julia, which uses different argument order conventions.

It’s been a while since I used R, but if I understand `%>%` correctly, I would argue that the biggest different between it and your suggestion is that the latter introduces values to the local scope, while R’s `%>%`, Julia’s `|>`, and the macros in `Lazy.jl` linked above don’t. I imagine that this is the major problem with your suggestion for most who are not enthusiastic about it.

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [February 28, 2017, 3:31pm UTC](https://discourse.julialang.org/t/rfc---as-ans/2326/23 "2017-02-28T15:31:18Z")

</div>

%\>% most definitely DOES introduce values to the local scope, it just uses . instead of \_ for the symbol

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [February 28, 2017, 3:32pm UTC](https://discourse.julialang.org/t/rfc---as-ans/2326/24 "2017-02-28T15:32:25Z")

</div>

> [@bramtayl](#):
>
> Like I showed above, only two corner cases in Base, each of which is caused by Julia using block syntax for lists/arguments. In fact, I was kicking around another proposal to add a new “arguments” block syntax/AST node which would allow you to pass arguments to a function in block form. This alternate proposal would allow macros to work correctly and remove the need for chaining behavior in Base.

No that is not at all a corner case. It’s just a bad macro implementation. One of the corner case is the one I mentioned above, macro writers or normal code writers in general can silently get an wrong result if they do not handle `_` correctly. It’ll be the only thing that’s readable and writable but reading from it is not expected to return the value written at all.

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [February 28, 2017, 3:39pm UTC](https://discourse.julialang.org/t/rfc---as-ans/2326/25 "2017-02-28T15:39:27Z")

</div>

There is NO way for a macro that chains blocks to recognize user defined macros which take arguments in block form, like MacroTools.@match. Previous versions of ChainRecursice.@chain have special cased to

1. Disable \_ immediately after assignments
2. Disable using \_ in type definitions

I eventually decided to drop both. The rules are much simpler now: I recommend users define types outside of chain blocks, and avoid using \_ to refer to named objects.

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [March 2, 2017, 12:36am UTC](https://discourse.julialang.org/t/rfc---as-ans/2326/26 "2017-03-02T00:36:23Z")

</div>

To avoid conflicts, it’s even possible to use two different symbols. I kind of like “it” for the chained item.

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [March 13, 2017, 5:34pm UTC](https://discourse.julialang.org/t/rfc---as-ans/2326/28 "2017-03-13T17:34:53Z")

</div>

I was thinking about this today and the documentation it would need. Something like

`_` always refers to the value of the previous line. Because it is gets overwritten after every line, it can also be safely used as a trash bin: that is, if you don’t want to ever access a value again, name it `_`.

---

<div class="post-metadata">

**Author:** ![jkbest2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jkbest2/32/7350_2.png) [@jkbest2](https://discourse.julialang.org/u/jkbest2)\
**Post date:** [March 13, 2017, 6:57pm UTC](https://discourse.julialang.org/t/rfc---as-ans/2326/29 "2017-03-13T18:57:01Z")

</div>

But I think the point of the current `_` is that anything assigned to it is not stored. Presumably this could have some performance benefits that would be lost if objects are allocated for a single line and then discarded.

It’s also not clear how this would deal with discarding multiple values, e.g.

```julia
X = randn(10, 10, 10)
nr, _, _ = size(X)

```

Is `_` in the next line the second or third dimension size of `X`?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [March 13, 2017, 7:03pm UTC](https://discourse.julialang.org/t/rfc---as-ans/2326/30 "2017-03-13T19:03:51Z")

</div>

I think his point is that it’ll be neither, which would be syntactically consistent but extremely confusing

---

<div class="post-metadata">

**Author:** ![shorty66](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shorty66/32/3254_2.png) [@shorty66](https://discourse.julialang.org/u/shorty66)\
**Post date:** [March 13, 2017, 7:07pm UTC](https://discourse.julialang.org/t/rfc---as-ans/2326/31 "2017-03-13T19:07:00Z")

</div>

i think `ans` is not so bad: Anyone who has used a calculator before knows it, and its only one keystroke longer than `_` .  
Why even bother?

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [March 13, 2017, 10:25pm UTC](https://discourse.julialang.org/t/rfc---as-ans/2326/32 "2017-03-13T22:25:16Z")

</div>

I’d be ok with ans. It currently doesn’t work inside blocks though

[Previous page](https://discourse.julialang.org/t/rfc---as-ans/2326.md?page=1)
