Make contains infix

why not make contains infix?

There are a few problems with making arbitrary functions infix. The first is “where do you stop?” That is, which functions become blessed to be infix and which don’t make the cut? The second is the question of parsing precedence. The precedence of in, for example, is quite clear, but it becomes unclear for arbitrary functions.

The convention thus far has been to keep ASCII functions/operators as prefix (of course with the exception of the standard mathematical operators and comparators) and provide Unicode symbols for infix equivalents. Take for example xor (neé $), which is called as xor(a, b) with the infix Unicode synonym \xor (AKA \veebar). This convention provides both clarity and consistency in code.

If you need infix containment checking, I recommend in and \subseteq depending on the circumstance. As an example,

julia> "abc" ⊆ "abcd" # equivalent to contains("abcd", "abc") if you don't care about order
true
2 Likes

Great! Thanks for the explanation.

Just as a remark though:

julia> "aa" ⊆ "asdfsdd"
true

julia> contains("asdfsdd", "aa")
false

Ah right, sorry, \subseteq doesn’t take order into account since it’s a set-based operation. My bad.

1 Like

No worries, thanks anyways!