sweet-js / sweet-core

Sweeten your JavaScript.
https://www.sweetjs.org
BSD 2-Clause "Simplified" License
4.59k stars 211 forks source link

How to define custom infix operators? #613

Closed dmitriz closed 7 years ago

dmitriz commented 7 years ago

Can I use Sweet e.g. to define a macro supporting equals operator (see https://github.com/fantasyland/fantasy-land#setoid) to be used as

a equals b

instead of the bulkier JS native way

a.equals(b)

Motivation

Mathematically speaking (I am a professional mathematician), the equivalence relation is fundamentally an infix operator, which is unnatural to be attached as method to one of the sides, especially when closely related infix operators like == are already part of the language.

disnet commented 7 years ago

This is on the roadmap. See #517.

gabejohnson commented 7 years ago

@disnet Can you reopen this? I'd prefer to keep a general design discussion about infix macros out #517.

disnet commented 7 years ago

@gabejohnson this request was for custom operators (the subject of #517) not infix macros.

gabejohnson commented 7 years ago

@disnet so it was. My mistake.