rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Modulus Operator

Open theRegex opened this issue 2 years ago • 4 comments

We're starting a new project that will use tons of animation and decided Rescript is a strong candidate - we love it's support for React. During our testing phase we discovered there seems to be no modulus operator, for exmaple:

let a = b mod c;

This is well implemented in Reason, https://reasonml.github.io/api/Pervasives.html#VAL(mod).

Are there any plans to add support for this in Rescript?

theRegex avatar Oct 29 '23 01:10 theRegex

No plans, but there is a built-in function that you can use with the pipe-operator

let a = b->mod(c)

ReScript tries to keep the reserved keyword space as small as possible and decided to make almost everything a function instead of an infix operator.

There exists also a prototype for custom infix operators which would enable you to assign the modulo function to an arbitrary string, but there seems not to be too much interest by the community. https://github.com/rescript-lang/rescript-compiler/pull/6076

OTOH I guess a fixed % as in JS would not hurt

fhammerschmidt avatar Oct 29 '23 23:10 fhammerschmidt

@fhammerschmidt Thanks, mod(a, b) works for what we need.

theRegex avatar Oct 30 '23 13:10 theRegex

Since ReScript is promoting syntactic features that make it look more like JS, I think it's a good idea to have the %, <<, >>, >>>, **, etc. be the same.

namenu avatar Oct 31 '23 12:10 namenu

@namenu I agree, although mod() works for me specifically - if ReScript is promoting syntatic features that resemble javascript then at minimal all basic arithmetic syntax should be honored - even more, almost all other languages support %, imo it's simple to get right. I'm not a huge fan of Typescript but atleast it allows all javascript abilities, devs use Rescript and Typescript because javascript is not good enough - so I'm not pushing to make Rescript exactly like javascript but ateast include the basic syntax that most strongly typed ML languages support.

On a good note, I like that Rescript is TRUE static typing and can really be a contender in the cross-platform space.

Can you guys please consider completing the arithmetic components of your compiler?

theRegex avatar Oct 31 '23 16:10 theRegex