coconut
coconut copied to clipboard
Define unicode operators
The unicode alternatives of the operators are brilliant. But is there any way that I can define my own one?
For example, I'm writing a function that checks whether a variable is an element of a set, which is either a finite one (a list, e.g., ⟦1,3,5,7,9⟧
), or a range over an ordered field (e.g., ⟦1…100, ℝ⟧
). I can define the infix function `elemOf`
(with back-ticks), but can I make an alias to the unicode symbols: ∈
, ∉
(without back-ticks), etc.?
Also, is it possible to map a data
constructor to a unicode symbol set? Like use ⟦...⟧
as an alternative to the set(...)
constructor.
Maybe this is a very stupid question, but can anyone point out some other references to solving my problem? I am a haskell
guy and I'm really new in coconut
and python
.
Duplicate of #4.
Duplicate of #4.
Yeah, I know how to define infix functions, thanks for the official documentation. I just wondered is it possible to define something like
# rather than
# def x `elemOf` xset=...
# use:
def x ∈ xset=...
infixr 2 ∈
then I can use:
if a ∈ ⟦1…100, ℝ⟧:
f'{a} is a small real number' ↦ print
Sorry, #4 is a very old issue and I don't think it's very clear what it's proposing (in fact I think it might predate the addition of infix functions). #4 is about adding syntax for defining custom Unicode operators, it just proposes to use the same syntax as for defining infix functions.
I am definitely interested in adding this functionality at some point, though it's a pretty big feature and also does have some drawbacks—e.g. making it harder to use Coconut code from Python code and requiring Unicode editor shortcuts to type Coconut—that will need to be worked around.
I see. Good to know it's interesting to you.
Anyway, thanks for creating Coconut
. I really like it.
Thanks; glad to hear it!
This is now live on coconut-develop>=2.0.0-post_dev4
! Check out the develop
documentation for more info.