I've not used units much so I'm a bit confused as to how they work...
Why does time := 69sec compile but size := 69kB does not?
Looking in FAN_HOME/etc/sys/units.txt there's a lot of definitions - but how do you reference them?
brianSun 14 Jul 2013
Literals like 69sec map to a Duration type which is implicitly based on time. The unit database is accessed with sys::Unit class.
Our commercial software SkySpark has a scripting language called Axon which actually does allow units with any number literal (based on Fantom unit database). It definitely has its pros and cons.
Thanks for the example. For some reason I was under the impression that all units in units.txt became Fantom literals - I think I confused it with Duration.
So to reiterate (for future ref):
there are no unit literals, just the sys::Unit class.
there are sys::Duration literals of ns, ms, sec, min, hr & day
SlimerDude Sun 14 Jul 2013
I've not used units much so I'm a bit confused as to how they work...
Why does
time := 69sec
compile butsize := 69kB
does not?Looking in
FAN_HOME/etc/sys/units.txt
there's a lot of definitions - but how do you reference them?brian Sun 14 Jul 2013
Literals like
69sec
map to a Duration type which is implicitly based on time. The unit database is accessed withsys::Unit
class.Our commercial software SkySpark has a scripting language called Axon which actually does allow units with any number literal (based on Fantom unit database). It definitely has its pros and cons.
ttmrichter Sun 14 Jul 2013
You'll want to check out the docs for
sys::Unit
.Short version:
69sec
is a duration literal and is part of the language grammar ( http://fantom.org/doc/docLang/Literals.html#duration ).69kB
is nothing at all unless you use thesys::Unit
classes and methods.Here would be some sample code:
SlimerDude Tue 16 Jul 2013
Cool,
Thanks for the example. For some reason I was under the impression that all units in
units.txt
became Fantom literals - I think I confused it withDuration
.So to reiterate (for future ref):
sys::Unit
class.sys::Duration
literals ofns, ms, sec, min, hr & day
Oh, and the
sys::Unit.convertTo
doc says:it should be:
brian Thu 18 Jul 2013
thanks, I fixed docs