brownplt / pyret-lang

The Pyret language.
Other
1.07k stars 110 forks source link

Feature request: allow underscores in number literals #1446

Open blerner opened 5 years ago

blerner commented 5 years ago

(Promoting from email thread to git issue, so we don't lose track)

Shriram: Consider using underscores to separate groupings of digits in number literals. E.g. in Rust,

    // Use underscores to improve readability!
    println!("One million is written as {}", 1_000_000u32);

Ben: That's not too hard to support, but it's subtler than you might think at first. Do you want to lexically enforce that underscores separate triads of digits (except the leading one)? If so, then it's extra friction to tweak your program and go from an iteration count of 1_500 items to a count of 15_000 items, or any other multi-digit magic constant in your program. Also, I don't think I'd like to complain "Pyret didn't understand your program at 10_00", since that's equally likely to be 1_000 or 10_000, as a 1-char edit distance.

ISTM that this is the sort of intuitively appealing thing that non-novice programmers might benefit more from, compared to novice programming explorers...


Shriram: Absolutely not, and here's why. In India we use a very different convention:

         1,000 — thousand
        10,000 — ten thousand
      1,00,000 — one lakh
     10,00,000 — ten lakhs
   1,00,00,000 — one crore
  10,00,00,000 — ten crores
 100,00,00,000 — hundred crores
1000,00,00,000 — thousand crores

(I'm not sure there's any terminology beyond "crore". It's not a very compositionally designed system.)

So I wouldn't want the language to force any punctuation convention.

I'm surprised by how many times (not very many, but still) I find myself writing a number (in a program) big enough that I'm not sure how many zeroes I've written without some punctuation help…

I imagine the physics teachers may appreciate it, too. Speed of light, etc.

shriram commented 5 years ago

https://srfi.schemers.org/srfi-169/srfi-169.html