mfey / units2 Goto Github PK
View Code? Open in Web Editor NEWA Clojure library for units of measurement.
License: Eclipse Public License 1.0
A Clojure library for units of measurement.
License: Eclipse Public License 1.0
javax.measure.unit has a compoundUnit
class that might be worth reproducing (or wrapping) in units2.
The typical use case might be for human-readable times (hh:mm:ss), but I can also see some use for compound units in proportions (e.g. a tasty recipe egg:flour:sugar:butter, or a neutrino flavour ratio) and vector quantities (e.g. a spatial vector x:y:z).
In all of the above, we read :
as "and"; we could also imagine compound units as encoding alternatives and read :
as "or" (e.g. a resource management game might have a cost payable in either in lumber or in stone, or a spacetime separation might be interpreted either as a distance or as a duration). Is this variation on compound units also reasonable to implement?
(makebaseunit <string>)
is currently just a layer of syntactic sugar over JScience's BaseUnit
.
If we try to use the name of a unit already defined in JScience's Unit/SI as the name of a new dimension, we get an exception. This is clearly a bug.
At the repl:
user=> (require '[units2.IFnUnit :refer [defbaseunit]])
nil
user=> (defbaseunit s "G")
#'user/s
user=> (defbaseunit s "H") ; Henry
CompilerException java.lang.IllegalArgumentException: Symbol H is associated to a different unit, compiling:(form-init######.clj:1:1)
user=> (defbaseunit s "I")
#'user/s
user=> (defbaseunit s "J") ; Joule
CompilerException java.lang.IllegalArgumentException: Symbol J is associated to a different unit, compiling:(form-init######.clj:1:1)
user=> (defbaseunit s "K") ; Kelvin, so expect exception, but it seems to work?
#'user/s
Intriguingly, using units from Unit/NonSI is just fine:
user=> (defbaseunit s "a") ; are
#'user/s
user=> (defbaseunit s "b")
#'user/s
user=> (defbaseunit s "c") ; speed of light
#'user/s
user=> (defbaseunit s "d") ; day
#'user/s
user=> (defbaseunit s "e") ; positron charge
#'user/s
An exception to this exceptional behaviour (!) occurs for Baseunit
s defined in Unit/SI themselves ("A", "cd", "K", "kg", "m", "mol", "s"), which seem to work just fine at a first glance but actually don't do what you'd expect!
user=> (defbaseunit s "A") ; ampere -> intensity
#'user/s
user=> (.getDimension s)
#object[javax.measure.unit.Dimension 0x29559cae "[I]"]
user=> (defbaseunit s "cd")
#'user/s
user=> (.getDimension s)
#object[javax.measure.unit.Dimension 0x22759915 "[L]²·[M]/[T]³"]
user=> (defbaseunit s "K")
#'user/s
user=> (.getDimension s)
#object[javax.measure.unit.Dimension 0x724b8f81 "[θ]"]
user=> (defbaseunit s "s") ; second -> time
#'user/s
user=> (.getDimension s)
#object[javax.measure.unit.Dimension 0x2b1781ab "[T]"]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.