# \\circ and parantheses

**URL:** <https://discourse.julialang.org/t/circ-and-parantheses/18196>\
**Category:** Internals & Design\
**Created:** [November 30, 2018, 10:24pm UTC](https://discourse.julialang.org/t/circ-and-parantheses/18196 "2018-11-30T22:24:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [November 30, 2018, 10:24pm UTC](https://discourse.julialang.org/t/circ-and-parantheses/18196/1 "2018-11-30T22:24:55Z")

</div>

The main thing that causes me to not use the `\circ` operator in julia as much as i do the mathematica equivalent (they use `@`) is, that I need to wrap everything in parantheses.  
I can see that this relates nicely to mathematical notation but what is the most common usecase for me, is that i wrote a function call like `sqrt(-2)` and then i notice “ahh… I need an `abs` there”.  
If i were to just insert a `\circ abs` between `sqrt` and `(`, that would go easily, but putting additional parantheses before `sqrt` and after `abs` killing the gain.  
Long story short: couldn’t `sqrt \circ abs(-2)` be parsed or lowered as `(sqrt \circ abs)(-2)`? That would also make it more similar to its brother `|>`.

---

<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:** [November 30, 2018, 10:36pm UTC](https://discourse.julialang.org/t/circ-and-parantheses/18196/2 "2018-11-30T22:36:49Z")

</div>

> [@BeastyBlacksmith](#):
>
> couldn’t `sqrt \circ abs(-2)` be parsed or lowered as `(sqrt \circ abs)(-2)` ?

It could, but that would be a breaking change so it couldn’t be made until Julia 2.0.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [November 30, 2018, 10:51pm UTC](https://discourse.julialang.org/t/circ-and-parantheses/18196/3 "2018-11-30T22:51:51Z")

</div>

I’m really surprised that it doesn’t do that.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [November 30, 2018, 11:21pm UTC](https://discourse.julialang.org/t/circ-and-parantheses/18196/4 "2018-11-30T23:21:10Z")

</div>

Whats the current behaviour useful for?

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [November 30, 2018, 11:31pm UTC](https://discourse.julialang.org/t/circ-and-parantheses/18196/5 "2018-11-30T23:31:57Z")

</div>

`abs(-2)` could return a function?

I don’t see `\circ` as that useful for cases like these, where `sqrt(abs(-2))` is at least as good. It’s nice for creating anonymous functions, though. `sqrt ∘ abs` is much better than `x->sqrt(abs(x))`.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [December 1, 2018, 6:51am UTC](https://discourse.julialang.org/t/circ-and-parantheses/18196/6 "2018-12-01T06:51:17Z")

</div>

Ah, to pass to map and such. Yeah I see.

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [December 1, 2018, 2:20pm UTC](https://discourse.julialang.org/t/circ-and-parantheses/18196/7 "2018-12-01T14:20:06Z")

</div>

Why would that be breaking? The current syntax would be still valid just not mandatory.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 1, 2018, 2:42pm UTC](https://discourse.julialang.org/t/circ-and-parantheses/18196/8 "2018-12-01T14:42:52Z")

</div>

> [@BeastyBlacksmith](#):
>
> Why would that be breaking?

Because it changes the meaning of existing 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:** [December 1, 2018, 3:11pm UTC](https://discourse.julialang.org/t/circ-and-parantheses/18196/9 "2018-12-01T15:11:52Z")

</div>

> [@mkborregaard](#):
>
> Whats the current behaviour useful for?

@DNF already suggested this, but let me elaborate: the current behavior is useful for working with higher order functions. The docstring for `∘` mentions

```julia
julia> map(uppercase∘first, ["apple", "banana", "carrot"])
3-element Array{Char,1}:
 'A'
 'B'
 'C'

```

and one can find other examples in the standard library, eg in `Pkg`

```julia
        for (name, uuids) in sort!(collect(unresolved), by=lowercase ∘ first)

```

It is emphatically not for `(f∘g)(x)`, for that `f(g(x))` is much more readable. The same applies to `!` for functions, eg `!f` is fine but `!f(x)` is preferred to `(!f)(x)`.

@BeastyBlacksmith: whenever you are wondering about a design choice or a use case for something in Julia, it is good practice to look at usage in `Base` and the standard library. Not everything is perfect, but many things are the result of a conscious decision and form a coherent whole.

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [January 27, 2020, 8:17pm UTC](https://discourse.julialang.org/t/circ-and-parantheses/18196/10 "2020-01-27T20:17:14Z")

</div>

> [@BeastyBlacksmith](#):
>
> Long story short: couldn’t `sqrt \circ abs(-2)` be parsed or lowered as `(sqrt \circ abs)(-2)` ? That would also make it more similar to its brother `|>` .

You can easily define your own operator which does this:

```julia
julia> (<|)(f, x) = f(x)
<| (generic function with 1 method)

julia> sqrt <| abs <| 2
1.4142135623730951

```
