PhEP: Underscores in Numeric Literals
This PhEP describes the extension of Pharo numeric literals to accepts (and ignore) underscore characters (`_` ASCII 95). Many languages (including Python https://peps.python.org/pep-0515/ , Java https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-... or Ruby) accept some forms of numeric literal that ignore _. The idea is to permit long literals that are still readable, eg. `1_000_000_000` is easier for a human than `100000000` especially since in the previous literal a zero is missing (I'm a tricky deceitful fellow). The details of the proposal are in the PR: https://github.com/pharo-project/pheps/pull/16 -- Jean Privat
Seems reasonable to me. I was just wishing for such a thing for exactly the reason you mention (keeping track of zeroes in large integer literals). AFAICT you've done a pretty good job laying out the possible error conditions. I think your option 1 makes senseâthe error-prone-ness is the sort of thing that could happen in theory, but I'm not too worried about in practice. Or option 2 is fine, I'm just not familiar enough with the parser to know how much harder it might be to implement. On Mon, Feb 13, 2023 at 1:54 PM Privat, Jean <privat.jean@uqam.ca> wrote:
This PhEP describes the extension of Pharo numeric literals to accepts (and ignore) underscore characters (`_` ASCII 95).
Many languages (including Python https://peps.python.org/pep-0515/ , Java https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-... or Ruby) accept some forms of numeric literal that ignore _.
The idea is to permit long literals that are still readable, eg. `1_000_000_000` is easier for a human than `100000000` especially since in the previous literal a zero is missing (I'm a tricky deceitful fellow).
The details of the proposal are in the PR: https://github.com/pharo-project/pheps/pull/16
-- Jean Privat
+1
El 13 feb. 2023, a las 20:37, Daniel Slomovits <daniels220@gmail.com> escribió:
Seems reasonable to me. I was just wishing for such a thing for exactly the reason you mention (keeping track of zeroes in large integer literals). AFAICT you've done a pretty good job laying out the possible error conditions. I think your option 1 makes senseâthe error-prone-ness is the sort of thing that could happen in theory, but I'm not too worried about in practice. Or option 2 is fine, I'm just not familiar enough with the parser to know how much harder it might be to implement.
On Mon, Feb 13, 2023 at 1:54 PM Privat, Jean <privat.jean@uqam.ca <mailto:privat.jean@uqam.ca>> wrote: This PhEP describes the extension of Pharo numeric literals to accepts (and ignore) underscore characters (`_` ASCII 95).
Many languages (including Python https://peps.python.org/pep-0515/ <https://peps.python.org/pep-0515/> , Java https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-... <https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-...> or Ruby) accept some forms of numeric literal that ignore _.
The idea is to permit long literals that are still readable, eg. `1_000_000_000` is easier for a human than `100000000` especially since in the previous literal a zero is missing (I'm a tricky deceitful fellow).
The details of the proposal are in the PR: https://github.com/pharo-project/pheps/pull/16 <https://github.com/pharo-project/pheps/pull/16>
-- Jean Privat
I like it. I assume that the enhancement will include converting strings to numbers '10_000' asNumber = 10_000 Noury On Feb 14 2023, at 9:30 am, Guillermo Polito <guillermopolito@gmail.com> wrote:
+1
El 13 feb. 2023, a las 20:37, Daniel Slomovits <daniels220@gmail.com (mailto:daniels220@gmail.com)> escribió: Seems reasonable to me. I was just wishing for such a thing for exactly the reason you mention (keeping track of zeroes in large integer literals). AFAICT you've done a pretty good job laying out the possible error conditions. I think your option 1 makes senseâthe error-prone-ness is the sort of thing that could happen in theory, but I'm not too worried about in practice. Or option 2 is fine, I'm just not familiar enough with the parser to know how much harder it might be to implement. On Mon, Feb 13, 2023 at 1:54 PM Privat, Jean <privat.jean@uqam.ca (mailto:privat.jean@uqam.ca)> wrote:
This PhEP describes the extension of Pharo numeric literals to accepts (and ignore) underscore characters (`_` ASCII 95).
Many languages (including Python https://peps.python.org/pep-0515/ , Java https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-... or Ruby) accept some forms of numeric literal that ignore _. The idea is to permit long literals that are still readable, eg. `1_000_000_000` is easier for a human than `100000000` especially since in the previous literal a zero is missing (I'm a tricky deceitful fellow). The details of the proposal are in the PR: https://github.com/pharo-project/pheps/pull/16 -- Jean Privat
participants (4)
-
Daniel Slomovits -
Guillermo Polito -
Noury Bouraqadi -
Privat, Jean