# Custom binary operators (with custom name)?

**URL:** <https://discourse.julialang.org/t/custom-binary-operators-with-custom-name/134141>\
**Category:** General Usage\
**Tags:** question, operator\
**Created:** [November 26, 2025, 1:14pm UTC](https://discourse.julialang.org/t/custom-binary-operators-with-custom-name/134141 "2025-11-26T13:14:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [November 26, 2025, 1:14pm UTC](https://discourse.julialang.org/t/custom-binary-operators-with-custom-name/134141/1 "2025-11-26T13:14:59Z")

</div>

Aside `+`, `*`, etc. is there a way to define my own binary operator, say `Foo` such that I can write something like:

```julia-auto
Foo(x,y) = [some funny op using x and y]
((x Foo b) Foo c) ....

```

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [November 26, 2025, 1:21pm UTC](https://discourse.julialang.org/t/custom-binary-operators-with-custom-name/134141/2 "2025-11-26T13:21:02Z")

</div>

You’re looking for custom infix operators - see also [★ is not an operator](https://discourse.julialang.org/t/is-not-an-operator/20221).

In short - no.

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [November 26, 2025, 1:27pm UTC](https://discourse.julialang.org/t/custom-binary-operators-with-custom-name/134141/3 "2025-11-26T13:27:21Z")

</div>

Saw it.  
Not even with a macro, e.g.

```julia-auto
@opdef Foo(x,y) = [some funny op using x and y]
@op ((x Foo b) Foo c) ....

```

?

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [November 26, 2025, 1:39pm UTC](https://discourse.julialang.org/t/custom-binary-operators-with-custom-name/134141/4 "2025-11-26T13:39:17Z")

</div>

I think with macros you could build something similar. Just remember that a macro needs to take valid Julia syntax as input and `(a foo b)` is not valid syntax but e.g. `[a foo b]` would be. So in principle you could cobbled together something. However, in practice I would advise against using macros to bend a part of Julia’s core syntax to your will like this. It will quickly make your code incomprehensible to anybody else and probably contain all sorts of edge cases.

---

<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:** [November 26, 2025, 2:40pm UTC](https://discourse.julialang.org/t/custom-binary-operators-with-custom-name/134141/5 "2025-11-26T14:40:18Z")

</div>

> [@Sukera](#):
>
> You’re looking for custom infix operators - see also [★ is not an operator](https://discourse.julialang.org/t/is-not-an-operator/20221). In short - no.

However, you have infinitely many choices available if you want to define a new infix operator: [On adjoints and custom postfix and infix operators - #35 by stevengj](https://discourse.julialang.org/t/on-adjoints-and-custom-postfix-and-infix-operators/12863/35)

(And there is even a hack to make completely arbitrary identifiers like `Foo` act infix-like, though I wouldn’t recommend using it in production code: see [Cursed Custom Infix Operators](https://discourse.julialang.org/t/cursed-custom-infix-operators/131915) and [InfixFunctions.jl](https://github.com/Ismael-VC/InfixFunctions.jl).)

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [November 26, 2025, 3:10pm UTC](https://discourse.julialang.org/t/custom-binary-operators-with-custom-name/134141/6 "2025-11-26T15:10:28Z")

</div>

> [@stevengj](#):
>
> And there is even a hack to make completely arbitrary identifiers like `Foo` act infix-like, though I wouldn’t recommend using it in production code: see [Cursed Custom Infix Operators](https://discourse.julialang.org/t/cursed-custom-infix-operators/131915) and [InfixFunctions.jl](https://github.com/Ismael-VC/InfixFunctions.jl).

Oh my, I was not aware of these at all! Cursed indeed..

---

<div class="post-metadata">

**Author:** ![moble](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moble/32/23535_2.png) [@moble](https://discourse.julialang.org/u/moble)\
**Post date:** [November 28, 2025, 5:43am UTC](https://discourse.julialang.org/t/custom-binary-operators-with-custom-name/134141/7 "2025-11-28T05:43:51Z")

</div>

Just for the record, I think it might be helpful to note the list of characters that “can follow an operator and be parsed as part of the operator”, which I don’t find documented anywhere. At least as of this writing, the list seems to be [here](https://github.com/JuliaLang/julia/blob/cf40898d56a5b32c6a2e97f61355440df36a7357/src/flisp/julia_extensions.c#L162-L180), which includes all Unicode combining characters (the categories [Mn](https://www.compart.com/en/unicode/category/Mn), [Mc](https://www.compart.com/en/unicode/category/Mc), and [Me](https://www.compart.com/en/unicode/category/Me)), as well as the explicit list of super- or sub-scripts and primes shown [here](https://github.com/JuliaLang/julia/blob/cf40898d56a5b32c6a2e97f61355440df36a7357/src/flisp/julia_opsuffs.h#L6).

(There is also a restriction to the range strictly between 0xA1 and 0x10ffff, but I think that’s just to make the checks more efficient, and doesn’t actually exclude any of the characters in those groups.)

It looks like most of [these operators](https://github.com/JuliaLang/julia/blob/cf40898d56a5b32c6a2e97f61355440df36a7357/src/julia-parser.scm#L11-L30), except for the groups listed in [this definition](https://github.com/JuliaLang/julia/blob/cf40898d56a5b32c6a2e97f61355440df36a7357/src/julia-parser.scm#L62-L65), can accept those suffixes.

---

<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:** [November 28, 2025, 8:02pm UTC](https://discourse.julialang.org/t/custom-binary-operators-with-custom-name/134141/8 "2025-11-28T20:02:22Z")

</div>

> [@moble](#):
>
> I think it might be helpful to note the list of characters that “can follow an operator and be parsed as part of the operator”, which I don’t find documented anywhere.

Please feel free to submit a documentation patch — you can do that easily with the edit button directly on github.

---

<div class="post-metadata">

**Author:** ![danielwe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielwe/32/35657_2.png) [@danielwe](https://discourse.julialang.org/u/danielwe)\
**Post date:** [November 29, 2025, 2:14am UTC](https://discourse.julialang.org/t/custom-binary-operators-with-custom-name/134141/9 "2025-11-29T02:14:26Z")

</div>

> [@moble](#):
>
> the range strictly between 0xA1 and 0x10ffff

The range of valid Unicode codepoints is 0x00 to 0x10ffff, so this check only rejects outright invalid codepoints on the upper end, and the basic ASCII character set (0x00 - 0x7F) plus a few non-printing control characters on the lower end.

---

<div class="post-metadata">

**Author:** ![moble](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moble/32/23535_2.png) [@moble](https://discourse.julialang.org/u/moble)\
**Post date:** [December 1, 2025, 5:42am UTC](https://discourse.julialang.org/t/custom-binary-operators-with-custom-name/134141/10 "2025-12-01T05:42:16Z")

</div>

PR here:

> <https://github.com/JuliaLang/julia/pull/60286>
>
> I've always found the documentation of operators a little incomplete; this PR ai…ms to improve the situation.
> 
> \- Add adjoint operator to the precedence table at correct precedence level between :: and exponentiation
> \- Explain exceptions to exponentiation precedence
> \- Include implicit multiplication by juxtaposition of numeric literals in precedence table
> \- Include arrows in precedence table
> \- Note that comparison operators can be chained with undefined evaluation order
> \- Explain that operators can be used in both infix and functional notation
> \- Note that new operators can be defined with suffixes, and show an example

Related PR that came up because it’s impossible to make an operator with superscript alpha (`\^alpha<tab>`) here:

> <https://github.com/JuliaLang/julia/pull/60285>
>
> @stevengj \[remarked\](https://github.com/JuliaLang/julia/pull/22089#issuecomment-…305479765) in his original PR introducing this file that the Unicode superscripts and subscripts are annoyingly scattered all over the place, and he seemed to miss out a few good ones.
> 
> Operators can be defined with suffixes, and still recognized as viable infix operators. All Unicode combining characters are allowed as suffixes, as well as a whitelist of sub- and superscripts defined in \`src/flisp/julia\_opsuffs.h\`. This list is incomplete, missing six items that are available with tab completion starting with either \`\\\_\` or \`\\^\`. Specifically, the superscripts alpha, epsilon, and Phi, and the subscript \<, \>, and schwa. I could take or leave this last one: it's not clear to me that schwa really qualifies for this list, but it would be the only item left out from the tab-completion list, which is the kind of thing that really bugs me when I'm the poor jerk who needs something that's not implemented for arbitrary reasons. Anyway, I think it's clear that the other items, at least, were left off unintentionally.
