# Is there a way to creat a function, which can be called on the right of arguments?

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-creat-a-function-which-can-be-called-on-the-right-of-arguments/87901>\
**Category:** New to Julia\
**Created:** [September 28, 2022, 4:55am UTC](https://discourse.julialang.org/t/is-there-a-way-to-creat-a-function-which-can-be-called-on-the-right-of-arguments/87901 "2022-09-28T04:55:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian1/32/49250_2.png) [@Brian1](https://discourse.julialang.org/u/Brian1)\
**Post date:** [September 28, 2022, 4:55am UTC](https://discourse.julialang.org/t/is-there-a-way-to-creat-a-function-which-can-be-called-on-the-right-of-arguments/87901/1 "2022-09-28T04:55:00Z")

</div>

```julia
A = [[1,2,3] [2,3,4]
#I can call adjoint like this
A'

```

So, is there way I can do this?

```julia
⁻¹(x::Matrix) = inv(x)

(A' * A)⁻¹

```

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [September 28, 2022, 4:56am UTC](https://discourse.julialang.org/t/is-there-a-way-to-creat-a-function-which-can-be-called-on-the-right-of-arguments/87901/2 "2022-09-28T04:56:27Z")

</div>

No, there’s no overloadable postfix operators.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [September 28, 2022, 5:23am UTC](https://discourse.julialang.org/t/is-there-a-way-to-creat-a-function-which-can-be-called-on-the-right-of-arguments/87901/3 "2022-09-28T05:23:12Z")

</div>

Yes, there are. But they are a hard coded set of symbols.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [September 28, 2022, 5:24am UTC](https://discourse.julialang.org/t/is-there-a-way-to-creat-a-function-which-can-be-called-on-the-right-of-arguments/87901/4 "2022-09-28T05:24:24Z")

</div>

> [@nsajko](#):
>
> No, there’s no postfix operators.

```julia-auto
julia> Meta.@lower M'
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope`
1 ─ %1 = var"'"(M)
└── return %1
))))

```

I think technically `'` is a postfix operator?

but:

```julia-auto
julia> var"'"
adjoint (generic function with 47 methods)

```

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [September 28, 2022, 7:38am UTC](https://discourse.julialang.org/t/is-there-a-way-to-creat-a-function-which-can-be-called-on-the-right-of-arguments/87901/5 "2022-09-28T07:38:47Z")

</div>

OK, I was wrong then.

`'` seems to be the only postfix operator then (except for things like `...`, which is an operator in a different sense):

```julia
julia> struct S
         n::Float64
         m::Float64
       end

julia> Base.adjoint(s::S) = S(s.m, s.n)

julia> s = S(3, 7)
S(3.0, 7.0)

julia> s'
S(7.0, 3.0)

```

It’s identified with Base.adjoint here:

> <https://github.com/JuliaLang/julia/blob/f1a0dd6b2476cf193c4001733e92638a7093b3e5/base/operators.jl#L587>

N.B: many other operators are directly overloadable, e.g. this works:

```julia
julia> Base.:(+)(a::S, b::S) = S(a.n+b.n, a.m+b.m)

julia> S(10, 20) + S(9, 2)
S(19.0, 22.0)

```

Relevant documentation: [Modules · The Julia Language](https://docs.julialang.org/en/v1.9-dev/manual/modules/#Qualified-names)

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [September 28, 2022, 7:45am UTC](https://discourse.julialang.org/t/is-there-a-way-to-creat-a-function-which-can-be-called-on-the-right-of-arguments/87901/6 "2022-09-28T07:45:44Z")

</div>

> [@nsajko](#):
>
> directly overloadable

well

```julia-auto
julia> struct S end

julia> var"'"
adjoint (generic function with 47 methods)

julia> Base.var"'"(x::S) = 3

julia> var"'"
adjoint (generic function with 48 methods)

julia> S()'
3

```
