History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: BOO-1
Type: Wish Wish
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Doug H
Reporter: Carlos Villela
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Boo

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

Created: 13/Jul/04 04:41 PM   Updated: 13/Mar/06 09:51 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

Issue Links:
Related
 
dependent


 Description  « Hide
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.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Carlos Villela - 27/Jul/04 05:47 PM
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


Doug H - 19/Aug/05 11:56 PM
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

Doug H - 23/Oct/05 09:00 PM
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:


Doug H - 23/Oct/05 09:01 PM
Actually see this link for the patch and builds of boo with the patch enabled:
http://codehaus.org/~dholton/boounits/

Doug H - 13/Mar/06 09:51 PM
No response on list about this, and patch is over 6 months old.