-
Notifications
You must be signed in to change notification settings - Fork 18
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
What is the benefit of allowing extensions on special numeric literal forms? #13
Comments
What did you find unconvincing about https://github.com/tc39/proposal-extended-numeric-literals/blob/master/README.md#motivation ? Cc @tabatkins |
Nothing in that section is relevant to my question. I'm asking something very specific and I'd appreciate it if you, as champion of this proposal, would take the time to consider my question instead of pointing me at some explainer prose that doesn't address my question at all. |
@rwaldron is specifically asking about using this on special numeric forms (bin, oct, hex), not the general motivation. (Presumably because, if we disallow it on hex, we can throw away the |
@tabatkins yep, you're exactly right on both accounts. |
Sorry for the delay in my response, I missed that your question was about different bases. Bases come up in
It'd seem to be a pretty odd omission to just not support other bases for something that's number-like. For this reason, BigInts support all the bases that Numbers do (even though I didn't have an especially strong use case for, say, octal in mind). |
CSS's only hex usage shows up only in the context of |
@littledan I agree with allowing the built-in BigIntLiteralSuffix for all existing bases, but there is still no compelling motivation to design this such that user extensions may be applied to all NumericLiteral forms.
In the absence of operator overloads, this isn't a compelling case. Consider the following: // How would user-level _n be defined to do anything useful here?
0x100000000000000000000000000000_n * 1;
// What does this do?
0x100000_n * 0x100000_n; A built-in BigInt extension (ie. BigIntLiteralSuffix) is the right solution for that, where these semantics, including operator overloading behavior, can be explicitly defined. |
In the BigInt proposal, we said we were walking down the trail that we'd later try to generalize with operator overloading, extensible literals and value types. Even if this proposal doesn't have operator overloading, the idea is that it would play well with a future operator overloading proposal. That's not to say that we have bullet-proof motivation! Maybe we should reconsider that package. But, I wrote up this proposal to try to begin walking down that road, where the idea was to have these multiple features playing well together. |
...More specifically, when would a program's source benefit from allowing the author to write things like:
0b01010101010101_px
,0b01010101010101_cm
,0b01010101010101_m
,0b01010101010101_$
0x0DDBA11_px
,0x0DDBA11_cm
,0x0DDBA11_m
,0x0DDBA11_$
0o0666_px
,0o0666_cm
,0o0666m
,0o0666_$
It would be nice to see real cases where a quantity of pixels are represented in hexadecimal, or quantity of centimeters in binary, or a quantity of dollars in octal.
The text was updated successfully, but these errors were encountered: