# Can we call a julia function %%?

**URL:** <https://discourse.julialang.org/t/can-we-call-a-julia-function/52809>\
**Category:** New to Julia\
**Tags:** function\
**Created:** [January 4, 2021, 5:07am UTC](https://discourse.julialang.org/t/can-we-call-a-julia-function/52809 "2021-01-04T05:07:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZdM87](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdm87/32/15353_2.png) [@ZdM87](https://discourse.julialang.org/u/ZdM87)\
**Post date:** [January 4, 2021, 5:07am UTC](https://discourse.julialang.org/t/can-we-call-a-julia-function/52809/1 "2021-01-04T05:07:30Z")

</div>

I was trying to name a function as `%%` but I did not succeed. I got:

```julia
ERROR: LoadError: syntax: "%" is not a unary operator

```

Can we name a function in julia as `%%`?

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [January 4, 2021, 6:21am UTC](https://discourse.julialang.org/t/can-we-call-a-julia-function/52809/2 "2021-01-04T06:21:25Z")

</div>

```julia
julia> var"%%"() = 1
%% (generic function with 1 method)

julia> var"%%"()
1

```

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [January 4, 2021, 8:33am UTC](https://discourse.julialang.org/t/can-we-call-a-julia-function/52809/3 "2021-01-04T08:33:41Z")

</div>

Why do you want a function named like this?  
If you want to define a new unary operator, you have to use one of the function names reserved for this purpose (e.g. `++`).

---

<div class="post-metadata">

**Author:** ![ZdM87](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdm87/32/15353_2.png) [@ZdM87](https://discourse.julialang.org/u/ZdM87)\
**Post date:** [January 4, 2021, 3:20pm UTC](https://discourse.julialang.org/t/can-we-call-a-julia-function/52809/4 "2021-01-04T15:20:53Z")

</div>

because I have a function that is very close to mod (%), so I tried to rename it %%. After all, I used a text name. But I was wondering the reason why I could not use %% as a name.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 4, 2021, 3:28pm UTC](https://discourse.julialang.org/t/can-we-call-a-julia-function/52809/5 "2021-01-04T15:28:23Z")

</div>

No particular reason. Support would need to be added to the parser for `%%` as an infix operator. There might, however, be objections or complications. Worth filing an issue though if you’re interested in this being available in a future version.

---

<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:** [January 4, 2021, 3:47pm UTC](https://discourse.julialang.org/t/can-we-call-a-julia-function/52809/6 "2021-01-04T15:47:29Z")

</div>

> [@StefanKarpinski](#):
>
> There might, however, be objections or complications.

Given that `%%` has no standardized meaning anyway (unlike eg `+`, `*`), and we have a zillion free Unicode operators for custom purposes, I am not sure I understand the motivation for complicating things just for the sake of `%%`.

Yes, I know R has it (for mod), and a whole zoo of other operators sandwiched between `%%`s. But they have no Unicode. Also, once operators end up taking up several characters, and aptly named function may just be less cryptic.

---

<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:** [January 4, 2021, 4:00pm UTC](https://discourse.julialang.org/t/can-we-call-a-julia-function/52809/7 "2021-01-04T16:00:44Z")

</div>

> [@ZdM87](#):
>
> because I have a function that is very close to mod (%), so I tried to rename it %%

You can call it `%′` (tab-complete `%\prime`) or ` %̂` (`%\hat`) or `%̃` (`%\tilde`), for example, or use a subscript or superscript after `%`.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 4, 2021, 5:41pm UTC](https://discourse.julialang.org/t/can-we-call-a-julia-function/52809/8 "2021-01-04T17:41:58Z")

</div>

Also, it might be good to reserve `%%` for `mod` since `%` means `rem`.

---

<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:** [January 5, 2021, 6:21am UTC](https://discourse.julialang.org/t/can-we-call-a-julia-function/52809/9 "2021-01-05T06:21:23Z")

</div>

I am not sure `mod` deserves an infix operator. There are around 50 uses of it in `Base`, and 40 more in the standard libraries (as opposed to `%` as `rem`, which has a few hundred).

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [January 5, 2021, 10:42am UTC](https://discourse.julialang.org/t/can-we-call-a-julia-function/52809/10 "2021-01-05T10:42:03Z")

</div>

> [@Tamas\_Papp](#):
>
> I am not sure `mod` deserves an infix operator.

If anything it’s `rem` that doesn’t deserve an infix operator. `mod` is by far the more useful of them whereas `rem` is a latent source of bugs whenever someone is careless with the sign of the first argument. (Yes, I know that hardware prefers `rem`, which is a historic mistake, and thus has its uses when performance is critical and you have full control of the signs.)

> [@Tamas\_Papp](#):
>
> There are around 50 uses of it in `Base` , and 40 more in the standard libraries (as opposed to `%` as `rem` , which has a few hundred).

Out of which the large majority is `x % Type`, where `rem` and `mod` are identical. Of the rest I didn’t at a quick glance see any case where either argument could be negative, so `mod` would have worked as well as `rem`.
