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 := 69seccompile butsize := 69kBdoes not?Looking in
FAN_HOME/etc/sys/units.txtthere's a lot of definitions - but how do you reference them?brian Sun 14 Jul 2013
Literals like
69secmap to a Duration type which is implicitly based on time. The unit database is accessed withsys::Unitclass.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:
69secis a duration literal and is part of the language grammar ( http://fantom.org/doc/docLang/Literals.html#duration ).69kBis nothing at all unless you use thesys::Unitclasses 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.txtbecame Fantom literals - I think I confused it withDuration.So to reiterate (for future ref):
sys::Unitclass.sys::Durationliterals ofns, ms, sec, min, hr & dayOh, and the
sys::Unit.convertTodoc says:m := Unit.find("meter") km := Unit.find("kilometer")it should be:
m := Unit.fromStr("meter") km := Unit.fromStr("kilometer")brian Thu 18 Jul 2013
thanks, I fixed docs