Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (def units {:cm 100
- :mm 1000
- :m 1
- :km 1/1000})
- (defn m-to-unit-helper [[k v]]
- (let [f (symbol (str "to-" (name k)))]
- `(defn ~f [m#] (* ~v m#))))
- (defmacro m-to-units [units-map]
- (let [funcs (map m-to-unit-helper units-map)]
- `(do ~@funcs)))
- ; complains with: Don't know how to create ISeq from: clojure.lang.Symbol
- (m-to-units units)
- ; To try and debug
- (defn debug [units-map]
- (let [funcs (map m-to-unit-helper units-map)]
- (clojure.pprint/pprint `(do ~@funcs))))
- ; see below
- (debug units)
- (do
- (clojure.core/defn
- to-mm
- [m__32709__auto__]
- (clojure.core/* 1000 m__32709__auto__))
- (clojure.core/defn
- to-m
- [m__32709__auto__]
- (clojure.core/* 1 m__32709__auto__))
- (clojure.core/defn
- to-cm
- [m__32709__auto__]
- (clojure.core/* 100 m__32709__auto__))
- (clojure.core/defn
- to-km
- [m__32709__auto__]
- (clojure.core/* 1/1000 m__32709__auto__)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement