Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modulus Operator #6455

Closed
theRegex opened this issue Oct 29, 2023 · 5 comments · Fixed by #7152
Closed

Modulus Operator #6455

theRegex opened this issue Oct 29, 2023 · 5 comments · Fixed by #7152

Comments

@theRegex
Copy link

theRegex commented Oct 29, 2023

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?

@fhammerschmidt
Copy link
Member

fhammerschmidt commented Oct 29, 2023

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.
#6076

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

@theRegex
Copy link
Author

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

@namenu
Copy link
Contributor

namenu commented Oct 31, 2023

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.

@theRegex theRegex reopened this Oct 31, 2023
@theRegex
Copy link
Author

@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?

@cometkim
Copy link
Member

cometkim commented Nov 9, 2024

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.

% infix operator is coming to ReScript v12, and works with all supported primitive types by #7057

any other existing JS operators too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

4 participants