Coder Social home page Coder Social logo

mfey / units2 Goto Github PK

View Code? Open in Web Editor NEW
21.0 0.0 2.0 248 KB

A Clojure library for units of measurement.

License: Eclipse Public License 1.0

Clojure 100.00%
clojure-library clojure units units-of-measurement dimensional-analysis physics clojure-spec

units2's People

Contributors

mfey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

units2's Issues

provide compound units

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?

leaky abstraction in `makebaseunit`

(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 Baseunits 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]"]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.