# Is it possible to define a \`\`+!\`\` function?

**URL:** https://discourse.julialang.org/t/is-it-possible-to-define-a-function/46475
**Category:** General Usage
**Created:** [September 11, 2020, 7:41pm UTC](https://discourse.julialang.org/t/is-it-possible-to-define-a-function/46475 "2020-09-11T19:41:52Z")
**Posts on this page:** 4
**Page:** 2

<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 16, 2020, 8:39pm UTC](https://discourse.julialang.org/t/is-it-possible-to-define-a-function/46475/21 "2020-09-16T20:39:50Z")

</div>

4 posts were merged into an existing topic: [Less than approx equals? \<≈](https://discourse.julialang.org/t/less-than-approx-equals/45436/20)

---

<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: [September 16, 2020, 8:33pm UTC](https://discourse.julialang.org/t/is-it-possible-to-define-a-function/46475/23 "2020-09-16T20:33:22Z")

</div>

> [@joa-quim](#):
>
> It’s not the correct answer. The correct is given by `acos.()` . See, not even the type is correct. And it’s not only `acos`

I think you have a fundamental misunderstanding here of linear algebra or are using the word ‘correct’ to instead mean ‘the thing that I meant’.

What you are seeing is no different from `*` versus `.*`.

```julia
julia> A = [1 2; 3 4]; B = [5 6; 7 8];

julia> A * B
2×2 Array{Int64,2}:
 19 22
 43 50

julia> A .* B
2×2 Array{Int64,2}:
  5 12
 21 32

```

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [September 16, 2020, 9:38pm UTC](https://discourse.julialang.org/t/is-it-possible-to-define-a-function/46475/24 "2020-09-16T21:38:11Z")

</div>

OK, I see what you mean. It’s computing the `acos` matrix of the type array member, though I was expecting to get the composite type on output as well.

```julia
julia> acos(G2.z)
2×2 Array{Complex{Float64},2}:
 0.651095+5.55112e-17im -0.71526+5.55112e-17im
  1.01153+0.0im 1.66263-2.22045e-16im

julia> acos(G2)
2×2 Array{Complex{Float64},2}:
 0.651095+5.55112e-17im -0.71526+5.55112e-17im
  1.01153+0.0im 1.66263-2.22045e-16im

```

but then why the same does not hold with `cos`?

```julia
julia> cos(G2.z)
2×2 Array{Float64,2}:
 0.827518 -0.365429
 0.516794 1.34431

julia> cos(G2)
ERROR: MethodError: no method matching GMT.GMTgrid(::String, ::String, ::Int64, ::Array{Float64,1}, ::Array{Float64,1}, ::Int64, ::Float64, ::String, ::String, ::String, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Complex{Float64},2}, ::String, ::String, ::String, ::String)
Closest candidates are:
  GMT.GMTgrid(::String, ::String, ::Int64, ::Array{Float64,1}, ::Array{Float64,1}, ::Int64, ::Union{Float32, Float64}, ::String, ::String, ::String, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{T,N}, ::String, ::String, ::String, ::String) where {T<:Real, N} at C:\Users\joaqu\.julia\dev\GMT\src\gmt_main.jl:2
Stacktrace:

```

---

<div class="post-metadata">

### Author: ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)
#### Post date: [September 16, 2020, 11:48pm UTC](https://discourse.julialang.org/t/is-it-possible-to-define-a-function/46475/25 "2020-09-16T23:48:52Z")

</div>

Broadcasting is most likely still the best solution here, but note that in Julia 1.6, `ꜝ` will be a valid operator suffix, so you can use `+ꜝ`, `-ꜝ`, `*ꜝ`, etc. as infix or prefix operators, without resorting to any hacks:

[https://github.com/JuliaLang/julia/pull/37542](https://github.com/JuliaLang/julia/pull/37542)

[Previous page](https://discourse.julialang.org/t/is-it-possible-to-define-a-function/46475.md?page=1)
