Boo

Generalize units in the syntax, allow pipeline to define new units

Details

  • Type: Wish Wish
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    0

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

Activity

Hide
Carlos Villela added a comment -

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

Show
Carlos Villela added a comment - 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
Hide
Doug H added a comment -

I worked out how to implement this, but the lexer rules are dependent on other changes to literals, mainly BOO-428 and BOO-424.
For future reference see also:
http://www.jscience.org/
http://groups-beta.google.com/group/boolang/browse_frm/thread/d9ec81d478006d75/ac7b44b467a78623?q=astliteralprocessor&rnum=2#ac7b44b467a78623

Show
Doug H added a comment - I worked out how to implement this, but the lexer rules are dependent on other changes to literals, mainly BOO-428 and BOO-424. For future reference see also: http://www.jscience.org/ http://groups-beta.google.com/group/boolang/browse_frm/thread/d9ec81d478006d75/ac7b44b467a78623?q=astliteralprocessor&rnum=2#ac7b44b467a78623
Hide
Doug H added a comment -

Initial stab at implementation posted here if anyone has feedback or design suggestions. I'll probably redo IAstUnit interface and the ProcessUnits step, and improve the convenience methods in UnitLiteralExpression and AbstractAstUnit..

ckknight is working on a units library:
http://ckknight.no-ip.org:8080/websvn/listing.php?repname=Units&path=%2F&sc=0
hopefully we can combine it with boo-1, and maybe it could be something in boo useful perhaps:

Show
Doug H added a comment - Initial stab at implementation posted here if anyone has feedback or design suggestions. I'll probably redo IAstUnit interface and the ProcessUnits step, and improve the convenience methods in UnitLiteralExpression and AbstractAstUnit.. ckknight is working on a units library: http://ckknight.no-ip.org:8080/websvn/listing.php?repname=Units&path=%2F&sc=0 hopefully we can combine it with boo-1, and maybe it could be something in boo useful perhaps:
Hide
Doug H added a comment -

Actually see this link for the patch and builds of boo with the patch enabled:
http://codehaus.org/~dholton/boounits/

Show
Doug H added a comment - Actually see this link for the patch and builds of boo with the patch enabled: http://codehaus.org/~dholton/boounits/
Hide
Doug H added a comment -

No response on list about this, and patch is over 6 months old.

Show
Doug H added a comment - No response on list about this, and patch is over 6 months old.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: