4 ms·
you would define values like weight = unit("10 kg") speed = unit("2.5 furlong per week")
by riffraff 7y ago
you would define values like
weight = unit("10 kg")
speed = unit("2.5 furlong per week")
- wodenokoto 7y agoMy imaginary units library would have been like Unit(float, unit_as_string) The free text version is pretty cool though
- choward 7y agoI would parse the free text version into something like your version. It could be used for user input from a text input field or the command line.
- Symbiote 7y agoEven further, presumably things like kg·m·s⁻², which (perhaps) this library can equate to Newtons.
- p6steve 7y agothis works now x for input and output ... the challenge for this kind of thing in bare code is that you need a LOT of namespace ... .oO maybe override the dot?
- iso-8859-1 7y agoBut what does strings have to do with it? Why can't those expressions be plain Perl, maybe with some overloaded operators? For example, import week, custom, si, type from stdlib.units weight = 10 * si.kg speed = 2.5 * (custom("furlong", type.LENGTH) / week)
- p6steve 7y agothis is also important - but imo, and in practice from perl5, the Units library experience is a lot richer if you can do both - especially for entry level programmers such as high school students - more on this to come in v2