# Creating a function called \*\*

**URL:** <https://discourse.julialang.org/t/creating-a-function-called/61464>\
**Category:** General Usage\
**Created:** [May 19, 2021, 9:09pm UTC](https://discourse.julialang.org/t/creating-a-function-called/61464 "2021-05-19T21:09:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pg261](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pg261/32/24270_2.png) [@pg261](https://discourse.julialang.org/u/pg261)\
**Post date:** [May 19, 2021, 9:09pm UTC](https://discourse.julialang.org/t/creating-a-function-called/61464/1 "2021-05-19T21:09:20Z")

</div>

Hi !

I’m trying to define an operator called \*\*, using something like

```julia
function **(a,b)
   return a+b+1 # or whatever
end

```

but Julia won’t let me – it’s just warning me that \*\* is not used for exponentiation. But \*\* is a good name for me!

(it works with ++ instead of \*\*, for example)

Any idea?

thanks!  
Pierre

---

<div class="post-metadata">

**Author:** ![leonandonayre](https://avatars.discourse-cdn.com/v4/letter/l/da6949/32.png) [@leonandonayre](https://discourse.julialang.org/u/leonandonayre)\
**Post date:** [May 19, 2021, 9:30pm UTC](https://discourse.julialang.org/t/creating-a-function-called/61464/2 "2021-05-19T21:30:45Z")

</div>

Interesting? But are you sure that it works with ++?

It does not work for me

> julia\> function ++(a,b)  
> return a+b+1 # or whatever  
> end  
> ++ (generic function with 1 method)
> 
> julia\> ++(1,2)  
> ERROR: MethodError: no method matching +(::Int64, ::Int64, ::Int64)  
> You may have intended to import Base.:+  
> Closest candidates are:  
> +(::Any, ::Any) at REPL[11]:1  
> Stacktrace:  
> [1] ++(a::Int64, b::Int64)  
> @ Main ./REPL[14]:2  
> [2] top-level scope  
> @ REPL[15]:1

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [May 19, 2021, 9:32pm UTC](https://discourse.julialang.org/t/creating-a-function-called/61464/3 "2021-05-19T21:32:41Z")

</div>

@leonandonayre Your example fails because of precedence of the `+` operator. You can run your function by calling `(++)(1, 2)`. For why the OP can’t even define `**`, maybe someone else can answer.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [May 19, 2021, 9:40pm UTC](https://discourse.julialang.org/t/creating-a-function-called/61464/5 "2021-05-19T21:40:01Z")

</div>

Yeah, `**` is special cased in the parser itself to throw this particular error: [https://github.com/JuliaLang/julia/blob/d7d2b0c692eb6ad409d7193ba8d9d42972cbf182/src/julia-parser.scm#L235](https://github.com/JuliaLang/julia/blob/d7d2b0c692eb6ad409d7193ba8d9d42972cbf182/src/julia-parser.scm#L235)

My guess was that this was to help guide Python users to the correct syntax in Julia, and after digging through the git history it turns out I was right:

[https://github.com/JuliaLang/julia/issues/633](https://github.com/JuliaLang/julia/issues/633)

[https://github.com/JuliaLang/julia/commit/113e77b06640c3d3355b917705c3b180a481a308](https://github.com/JuliaLang/julia/commit/113e77b06640c3d3355b917705c3b180a481a308)

---

<div class="post-metadata">

**Author:** ![pg261](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pg261/32/24270_2.png) [@pg261](https://discourse.julialang.org/u/pg261)\
**Post date:** [May 20, 2021, 8:03am UTC](https://discourse.julialang.org/t/creating-a-function-called/61464/6 "2021-05-20T08:03:46Z")

</div>

Thanks for your answers 🙂 I’ll just use a different name.

---

<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:** [May 20, 2021, 3:02pm UTC](https://discourse.julialang.org/t/creating-a-function-called/61464/7 "2021-05-20T15:02:25Z")

</div>

See [https://github.com/JuliaLang/julia/pull/39089](https://github.com/JuliaLang/julia/pull/39089). We just didn’t really come up with a convincing enough use case at the time. If you have a concrete use for this, feel free to chime in on the discussion there.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 20, 2021, 3:06pm UTC](https://discourse.julialang.org/t/creating-a-function-called/61464/8 "2021-05-20T15:06:51Z")

</div>

> [@pg261](#):
>
> I’ll just use a different name.

Take a look at the unicode symbols, maybe there is one even better for your use case:

[https://docs.julialang.org/en/v1/manual/unicode-input/](https://docs.julialang.org/en/v1/manual/unicode-input/)

for example, this one:

✳ : `\:eight_spoked_asterisk:`

(that is a joke 🙂 )

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [May 20, 2021, 3:34pm UTC](https://discourse.julialang.org/t/creating-a-function-called/61464/9 "2021-05-20T15:34:31Z")

</div>

May I suggest 💫 (`\:dizzy:`), which in some fonts has two stars.

Edited to add - when I actually posted this the symbol changed after sending to a single star, I meant this:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/e/1e544825802c6892460d19c6066db303c12d1604.png)

---

<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:** [May 20, 2021, 5:38pm UTC](https://discourse.julialang.org/t/creating-a-function-called/61464/10 "2021-05-20T17:38:06Z")

</div>

> [@nilshg](#):
>
> May I suggest 💫 ( `\:dizzy:` ), which in some fonts has two stars.

Note that emoji like `:dizzy:` and `:eight_spoked_asterisk:` are in Unicode category `So` (Symbol, other) and are typically not parsed as infix operators by Julia.

That being said, there are plenty of infix operators to choose from. My visual favorite is `⨳` (`\smashtimes`).

---

<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:** [May 20, 2021, 5:47pm UTC](https://discourse.julialang.org/t/creating-a-function-called/61464/11 "2021-05-20T17:47:08Z")

</div>

Another thing you’re allowed to do is stick unicode modifiers on infix operators to make new operators with the same precence. For example:

```julia
julia> *̂(a,b) = a + b
*̂ (generic function with 1 method)

julia> 1 *̂ 2
3

julia> *²(a, b) = (a * b)^2
*² (generic function with 1 method)

julia> 2 *² 3
36

```

---

<div class="post-metadata">

**Author:** ![pg261](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pg261/32/24270_2.png) [@pg261](https://discourse.julialang.org/u/pg261)\
**Post date:** [May 20, 2021, 9:22pm UTC](https://discourse.julialang.org/t/creating-a-function-called/61464/12 "2021-05-20T21:22:44Z")

</div>

In fact, I am now using \cdot (how do I make it visible in this post??)
