# Right-handed unary operator?

**URL:** <https://discourse.julialang.org/t/right-handed-unary-operator/6280>\
**Category:** General Usage\
**Created:** [October 6, 2017, 2:46am UTC](https://discourse.julialang.org/t/right-handed-unary-operator/6280 "2017-10-06T02:46:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [October 6, 2017, 2:46am UTC](https://discourse.julialang.org/t/right-handed-unary-operator/6280/1 "2017-10-06T02:46:01Z")

</div>

Is it possible to define unary operators that act from the right?  
For example, typically `!` is placed on the right for factorial like `5!`.

Specifically, I’d like to define some operation like `xˡ` and `xʳ` or alternatively `x^l` and `x^r`.

If that’s not possible, how can I define it in the same way as `+` and `-` are defined so that `+1` yields 1 and `-1` yields -1 value without using parenthesis like `+(1)` or `-(1)`. How can I define the function `ʳ(x) = foo(x)` so that I can use it without parenthesis like `ʳx`, preferably with a right-handedness so that I can write `xʳ`.

---

<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:** [October 6, 2017, 3:04am UTC](https://discourse.julialang.org/t/right-handed-unary-operator/6280/2 "2017-10-06T03:04:10Z")

</div>

The [only unary operators](https://github.com/JuliaLang/julia/blob/7504a381631328bd8e6411a179e12977b0d0a41c/src/julia-parser.scm#L99-L100) in Julia are `<: >: + - ! ~ ¬ √ ∛ ∜`, all of which are parsed as acting from the left. _Edit:_ plus `'` and `.'`, of course, which are postfix operators.

You can’t define arbitrary new symbols as unary operators, only use/extend/redefine those that are already parsed that way. (Nor can you define arbitrary symbols to be binary operators, but this is less of a limitation since there are many more Unicode binary operators to choose from, particularly in 0.7 now that you can add operator suffixes/decorators via #22089.)

---

<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:** [October 6, 2017, 3:05am UTC](https://discourse.julialang.org/t/right-handed-unary-operator/6280/3 "2017-10-06T03:05:27Z")

</div>

And superscripts, in particular, are too useful as part of identifiers to give them up for operators. But note that in 0.7 you can add superscripts to operators, e.g. you can define an operator `+ʳ`.

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [October 6, 2017, 11:34am UTC](https://discourse.julialang.org/t/right-handed-unary-operator/6280/4 "2017-10-06T11:34:29Z")

</div>

[I too would love to have more unary operators](https://github.com/JuliaLang/julia/issues/18139).

---

<div class="post-metadata">

**Author:** ![dazsmith](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@dazsmith](https://discourse.julialang.org/u/dazsmith)\
**Post date:** [May 15, 2019, 8:18pm UTC](https://discourse.julialang.org/t/right-handed-unary-operator/6280/5 "2019-05-15T20:18:24Z")

</div>

Note for those finding this later:

To overload the postfix operator `'`, you can import `adjoint` from `LinearAlgebra`, and overload the `adjoint` function. It appears that the postfix operator `'` always points to whatever is the definition of `adjoint`, including any overloads.

For example, this approach is used in the definition of `'` as a postfix operator for differentiation in ApproxFun.
