# help with "-\>"

**URL:** <https://discourse.julialang.org/t/help-with/15107>\
**Category:** New to Julia\
**Created:** [September 18, 2018, 4:59am UTC](https://discourse.julialang.org/t/help-with/15107 "2018-09-18T04:59:02Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![qsong](https://avatars.discourse-cdn.com/v4/letter/q/d07c76/32.png) [@qsong](https://discourse.julialang.org/u/qsong)\
**Post date:** [September 18, 2018, 4:59am UTC](https://discourse.julialang.org/t/help-with/15107/1 "2018-09-18T04:59:02Z")

</div>

hello,

It seems “-\>” could be one head of Expr, but I always got tuple head when trying  
:(:-\>, :a, :a)

I was trying to know a little more about “-\>” and searched the document & google with no luck.  
I also searched source code and found :lambda  
lam = Expr(:lambda, g.argnames, …

Still, not much helpful. So where is the Symbol “-\>” defined?

Thanks!

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [September 18, 2018, 5:09am UTC](https://discourse.julialang.org/t/help-with/15107/2 "2018-09-18T05:09:57Z")

</div>

It is used for lambdas (aka anonymous functions): `x -> x+ 2`. So try something like `:(a -> b)` to get an Expr with `->`.

---

<div class="post-metadata">

**Author:** ![qsong](https://avatars.discourse-cdn.com/v4/letter/q/d07c76/32.png) [@qsong](https://discourse.julialang.org/u/qsong)\
**Post date:** [September 18, 2018, 6:43am UTC](https://discourse.julialang.org/t/help-with/15107/3 "2018-09-18T06:43:03Z")

</div>

yes, I do know :(a → b). As “-\>” is a head, could you write it in the form :(:-\>, …? Tks!

---

<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:** [September 18, 2018, 7:02am UTC](https://discourse.julialang.org/t/help-with/15107/4 "2018-09-18T07:02:05Z")

</div>

You can construct an expression using `Expr`, but that relies on internals which may (1) change, (2) be complicated, or in some cases (3) irrelevant. Do what @mauro3 suggested, and construct expressions using interpolation, eg `:($(aexpr) -> $(bexpr))`

---

<div class="post-metadata">

**Author:** ![qsong](https://avatars.discourse-cdn.com/v4/letter/q/d07c76/32.png) [@qsong](https://discourse.julialang.org/u/qsong)\
**Post date:** [September 18, 2018, 8:27am UTC](https://discourse.julialang.org/t/help-with/15107/5 "2018-09-18T08:27:01Z")

</div>

thanks for the reply. I guess I just would like to know a little bit about the internals of “-\>”, or the source code.

---

<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:** [September 18, 2018, 8:50am UTC](https://discourse.julialang.org/t/help-with/15107/6 "2018-09-18T08:50:03Z")

</div>

If you are interested in internals, just use something like

```julia
julia> dump(:(a -> b))
Expr
  head: Symbol ->
  args: Array{Any}((2,))
    1: Symbol a
    2: Expr
      head: Symbol block
      args: Array{Any}((2,))
        1: LineNumberNode
          line: Int64 1
          file: Symbol REPL[39]
        2: Symbol b

```

to explore.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [September 18, 2018, 8:51am UTC](https://discourse.julialang.org/t/help-with/15107/7 "2018-09-18T08:51:42Z")

</div>

Maybe this also: `Base.Meta.@lower a -> b`

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [September 18, 2018, 9:10am UTC](https://discourse.julialang.org/t/help-with/15107/8 "2018-09-18T09:10:46Z")

</div>

> [@qsong](#):
>
> It seems “-\>” could be one head of Expr, but I always got tuple head when trying  
> :(:-\>, :a, :a)

If you quote a tuple you get a quoted tuple. If you want the first argument to be the head of an `Expr`, construct an `Expr`.

```julia
julia> Expr(:->, :a, :a)
:(a->a)

```

---

<div class="post-metadata">

**Author:** ![qsong](https://avatars.discourse-cdn.com/v4/letter/q/d07c76/32.png) [@qsong](https://discourse.julialang.org/u/qsong)\
**Post date:** [September 18, 2018, 12:11pm UTC](https://discourse.julialang.org/t/help-with/15107/9 "2018-09-18T12:11:57Z")

</div>

from Meta.lower I see Expr(:-\>, …) is based on Expr(:method, …(julia v1.0)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 18, 2018, 12:19pm UTC](https://discourse.julialang.org/t/help-with/15107/10 "2018-09-18T12:19:06Z")

</div>

> [@Tamas\_Papp](#):
>
> You can construct an expression using `Expr` , but that relies on internals which may (1) change, (2) be complicated

Note that the contents of `Expr` nodes are not “internals”, they are part of the exported Julia API; it is often necessary to use them when writing macros, for example. Breaking changes to `Expr` nodes should not be made in the Julia 1.x timeline.

---

<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:** [September 18, 2018, 1:40pm UTC](https://discourse.julialang.org/t/help-with/15107/11 "2018-09-18T13:40:37Z")

</div>

> [@stevengj](#):
>
> Note that the contents of `Expr` nodes are not “internals”

I am confused then; since they are [documented](https://docs.julialang.org/en/stable/devdocs/ast/) under the “Documentation of Julia’s Internals” part of the manual.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 18, 2018, 2:04pm UTC](https://discourse.julialang.org/t/help-with/15107/12 "2018-09-18T14:04:24Z")

</div>

> [@Tamas\_Papp](#):
>
> I am confused then; since they are [documented](https://docs.julialang.org/en/stable/devdocs/ast/) under the “Documentation of Julia’s Internals” part of the manual.

That section is about the _lowered_ form of the AST. The surface-syntax `Expr` nodes are documented in the [metaprogramming](https://docs.julialang.org/en/v1/manual/metaprogramming/) section of the manual, though the documentation could be more complete. Because macros directly access the surface-syntax `Expr` type, it is part of the API that cannot be changed without breaking valid user code.

---

<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:** [September 18, 2018, 2:37pm UTC](https://discourse.julialang.org/t/help-with/15107/13 "2018-09-18T14:37:43Z")

</div>

Thanks. So plain vanilla user-written macros are not supposed to encounter or expect lowered forms?

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [September 18, 2018, 2:45pm UTC](https://discourse.julialang.org/t/help-with/15107/14 "2018-09-18T14:45:43Z")

</div>

Lowering happens after macro expansion.

---

<div class="post-metadata">

**Author:** ![jeff.bezanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff.bezanson/32/48_2.png) [@jeff.bezanson](https://discourse.julialang.org/u/jeff.bezanson)\
**Post date:** [September 18, 2018, 3:18pm UTC](https://discourse.julialang.org/t/help-with/15107/15 "2018-09-18T15:18:33Z")

</div>

Later in that section there is a list of surface AST forms, but I agree it would make sense to move it to the metaprogramming chapter.
