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

Add support for hexadecimal, octal and binary notation #1796

Closed
yannham opened this issue Jan 31, 2024 · 2 comments · Fixed by #1798
Closed

Add support for hexadecimal, octal and binary notation #1796

yannham opened this issue Jan 31, 2024 · 2 comments · Fixed by #1798

Comments

@yannham
Copy link
Member

yannham commented Jan 31, 2024

Is your feature request related to a problem? Please describe.
It's common to input numbers in a different base than the decimal system (especially if they're taken from a source where they're represented that way). Many languages have a support for different bases, usually at least binary, octal and decimal, in the format of number literals.

Describe the solution you'd like

Extend the syntax of number literals to accept hexadecimal notation (0x prefix), octal (0o prefix) and binary (0b).

Describe alternatives you've considered

Do nothing, and simply require the users to convert their numbers to base 10.

Additional context

Initially proposed by @Quantum64 on Discord.

@yannham yannham added this to the Next minor (1.5) milestone Jan 31, 2024
@yannham yannham self-assigned this Jan 31, 2024
@vkleen
Copy link
Member

vkleen commented Jan 31, 2024

One small caveat here ist that Nickel number literals are rational numbers by default. Since so few languages make actual use of hexadecimal fractional numbers, I think we should at least start by only allowing integers to be written in bases other than 10.

@yannham
Copy link
Member Author

yannham commented Jan 31, 2024

Fair enough. I tried in the console out of curiosity and JavaScript also only accepts integers to be written in hexadecimal notation (not that JavaScript is often a good model as far as language design goes, but at least it's a data point of another language with only one type of number 🤷 )

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

Successfully merging a pull request may close this issue.

2 participants