Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leaky abstraction in makebaseunit #2

Open
mfey opened this issue Oct 8, 2017 · 0 comments
Open

leaky abstraction in makebaseunit #2

mfey opened this issue Oct 8, 2017 · 0 comments
Labels

Comments

@mfey
Copy link
Owner

mfey commented Oct 8, 2017

(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]"]
@mfey mfey added the bug label Oct 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant