Last active
August 29, 2015 14:18
-
-
Save dyba/1d9a3551e2bb9f75111c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; WIP... | |
(defn quote-units | |
[units] | |
(let [syms (filter symbol? units) | |
vals (filter number? units)] | |
(interleave (map (fn [u] `'~u) syms) vals))) | |
(defmacro defunits | |
[quantity base-unit & units] | |
`(defmacro ~(symbol (str "unit-of-" quantity)) | |
[val# un#] | |
(* val# (case un# ~@(quote-units units))))) | |
;; above should create this... | |
(defmacro unit-of-time | |
[value unit] | |
`(* ~value | |
~(case unit | |
s 1 | |
m 60 | |
h 3600 | |
d 86400 | |
ms 1/1000 | |
us 1/1000000))) | |
;; Goal | |
(defunits time s | |
m 60 | |
h 3600 | |
d 86400 | |
ms 1/1000 | |
us 1/100000) | |
;; sample test | |
(unit-of-time 1 d) | |
;; => 86400 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment