Details
-
Type:
Wish
-
Status:
Closed
-
Priority:
Major
-
Resolution: Won't Fix
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
On lots of today's generic programming languages, we have a really simplified concept of 'units':
double foo = 10.5d
float bar = 10.5f
long fubar = 10L
These were added to these languages to disambiguate typing when defining constants, but Boo also added a very interesting type directly to the syntax, TimeSpans:
Thread.Sleep(50ms)
This wish is for a more generic way of defining these 'units'. Today, Boo has miliseconds, seconds, minutes, hours, days, weeks
, months
and years
, but that is only the beginning. Things start to get really interesting if it's possible to do this directly at the programming level:
distance = 100m * 3in // meters and inches
position = (142px, 183px) // pixels
amount = 100.0USD + 1.50GBP // dollars and pounds
capacity = 2cm3 + 4l + 2g // cubic centimeters, liters, gallons
binary = 01010101110b // binary
This could be implemented by generalizing the rules in the Antlr grammar so that every number constant is defined with an optional unit. Operators should take units into account, and be able to convert them (or throw something like an IncompatibleUnitException).
It should be possible to define new units, and, to avoid name clashes (m for meters and minutes, for example), there should be a way to import them.
Issue Links
| This issue is related to: | ||||
| BOO-84 | Marking strings for i18n |
|
|
|
| This issue depends upon: | ||||
| BOO-423 | Timespan literals won't work with numbers starting with decimal point |
|
|
|
| BOO-509 | Custom compiler error and warning messages |
|
|
|
| BOO-428 | Check negative number literals at compile time |
|
|
|
| BOO-425 | Digit grouping for readability |
|
|
|
| BOO-424 | Exponential notation |
|
|
|
| This issue is depended upon by: | ||||
| BOO-435 | decimal literal |
|
|
|
| BOO-429 | Complex number literals and builtin type |
|
|
|
Also, this can solve the char primitive problem, as boo uses single and double quotes for strings:
myChar = "a"c
and even unicode stuff (don't know if this applies to the CLR):
myUnicodeChar = "a"u
anotherUnicodeChar = 0x0009u