# Infix function notation for \`setdiff\`

**URL:** <https://discourse.julialang.org/t/infix-function-notation-for-setdiff/38381>\
**Category:** General Usage\
**Tags:** infix\
**Created:** [April 28, 2020, 4:33pm UTC](https://discourse.julialang.org/t/infix-function-notation-for-setdiff/38381 "2020-04-28T16:33:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)\
**Post date:** [April 28, 2020, 4:33pm UTC](https://discourse.julialang.org/t/infix-function-notation-for-setdiff/38381/1 "2020-04-28T16:33:44Z")

</div>

I’m looking for suggestions for an infix function for `Base.setdiff`. I’ve seen `$\setminus$` (`∖`) used, but that’s not a valid identifier character probably because it’s often indistinguishable from backslash (`\`) (Ah yes: [better error for help on invalid characters · Issue #30506 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/30506))

I don’t want to pun on the division operation.

The only idea I have is `$\ominus$` (`⊖`). Another possibility is defining a wrapper type `Complement`, specialize on `intersect`, and allow writing `A ∩ ¬B`. Any others?

---

<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:** [April 28, 2020, 4:55pm UTC](https://discourse.julialang.org/t/infix-function-notation-for-setdiff/38381/2 "2020-04-28T16:55:13Z")

</div>

You could use `-̂` (typed `-\hat<TAB>`).

```julia
julia> -̂(A, B) = Base.setdiff(A, B)
-̂ (generic function with 1 method)

julia> Set([1,2,3,4]) -̂ Set([1, 4])
Set{Int64} with 2 elements:
  2
  3

```

Note however that this character won’t show up well on many displays.

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [April 28, 2020, 4:56pm UTC](https://discourse.julialang.org/t/infix-function-notation-for-setdiff/38381/3 "2020-04-28T16:56:02Z")

</div>

I thought `\` was the standard notation for this, but `setdiff([1 2; 3 4], [4,5])` and `[1 2; 3 4] \ [4,5]` already mean different things.

Currently `¬` doesn’t parse as infix. But `~` does, and has no two-argument methods. Not sure I’ve seen either used, but the set operation is pronounced “A not B” right?

---

<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:** [April 28, 2020, 5:40pm UTC](https://discourse.julialang.org/t/infix-function-notation-for-setdiff/38381/4 "2020-04-28T17:40:29Z")

</div>

Or `-ₛ` (`-\_s<TAB>`), which I’m guessing has more widespread font support.

I would recommend defining such synonyms as constants rather than as new functions:

```julia
const -ₛ = setdiff

```

That way, online help (`?-ₛ`) and other things specialized for `setdiff` will continue to work.

---

<div class="post-metadata">

**Author:** ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)\
**Post date:** [April 28, 2020, 5:45pm UTC](https://discourse.julialang.org/t/infix-function-notation-for-setdiff/38381/5 "2020-04-28T17:45:16Z")

</div>

Thanks for the suggestion. No program (browser or terminal) I’ve tried so far has been able to render it, unfortunately. It’s [ₛ - LATIN SUBSCRIPT SMALL LETTER S (U+209B)](http://unicode.scarfboy.com/?s=000209b) for others who don’t have it rendering either.

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [April 28, 2020, 6:40pm UTC](https://discourse.julialang.org/t/infix-function-notation-for-setdiff/38381/6 "2020-04-28T18:40:41Z")

</div>

That’s a subscript `s`, which also doesn’t seem to work anywhere for me. Superscript `s` works better for me, so you could do `const \ˢ = setdiff` except that this is a pain to type!
