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

Number.range(from) for infinite range #14

Closed
bergus opened this issue Mar 13, 2020 · 5 comments
Closed

Number.range(from) for infinite range #14

bergus opened this issue Mar 13, 2020 · 5 comments

Comments

@bergus
Copy link

bergus commented Mar 13, 2020

I would suggest using undefined in the second parameter (to) to signal an infinite range. This would elegantly solve the BigInt problem #8, and seems more consistent to me than the overload that makes range(n) equivalent to range(0, n).
The resulting Range instance would basically "not have an .end", i.e. Number.range(n).end === undefined.

The only downside would be that for (x of Number.range(a, b)) would no longer desugar to the simple for (x = a; x < b; x++) but rather to something like for (x = a; !(x >= b); x++). (I would however prefer to simply offer second desugaring in explanations, namely that for (x of Number.range(a, undefined))for (x = a; true; x++).)

If there is a large want for the isAcceptAlias feature, I would propose having a separate rangeTo method, where Number.rangeTo(n)Number.range(0, n).

@ljharb
Copy link
Member

ljharb commented Mar 13, 2020

That would also mean that omitting the second argument would implicitly be Infinity. That seems problematic.

@bergus
Copy link
Author

bergus commented Mar 14, 2020

Why do you consider that to be a problem? I think it's a feature. Number.range(a, b) corresponds to the range [a .. b-1], and Number.range(a) corresponds to the range [a .. ]. I consider it confusing to have it swap sides if the second argument is omitted.

@Jack-Works
Copy link
Member

Jack-Works commented Mar 14, 2020

The range(to) semantics is inspired by Python style (https://docs.python.org/3.5/library/functions.html#func-range).

But if there are different thoughts on the overload, maybe it's better to not allow any kind of overload.

@hax
Copy link
Member

hax commented Mar 17, 2020

I would prefer explicitness. There is no much benefit to save several keystrokes.

@Jack-Works
Copy link
Member

Jack-Works commented Jun 10, 2020

It seems like there's less support for (from) compared to (to). So I decided to close this issue, but this doesn't mean I'll choose the (to) overload.

I will stay on the current design until I consider it more clearly (or it's become a consensus that we should add (to) overload).

maybe it's better to not allow any kind of overload.

Thanks for your suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants