Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. (def units {:cm 100
  2. :mm 1000
  3. :m 1
  4. :km 1/1000})
  5.  
  6. (defn m-to-unit-helper [[k v]]
  7. (let [f (symbol (str "to-" (name k)))]
  8. `(defn ~f [m#] (* ~v m#))))
  9.  
  10. (defmacro m-to-units [units-map]
  11. (let [funcs (map m-to-unit-helper units-map)]
  12. `(do ~@funcs)))
  13.  
  14. ; complains with: Don't know how to create ISeq from: clojure.lang.Symbol
  15. (m-to-units units)
  16.  
  17. ; To try and debug
  18. (defn debug [units-map]
  19. (let [funcs (map m-to-unit-helper units-map)]
  20. (clojure.pprint/pprint `(do ~@funcs))))
  21.  
  22. ; see below
  23. (debug units)
  24.  
  25. (do
  26. (clojure.core/defn
  27. to-mm
  28. [m__32709__auto__]
  29. (clojure.core/* 1000 m__32709__auto__))
  30. (clojure.core/defn
  31. to-m
  32. [m__32709__auto__]
  33. (clojure.core/* 1 m__32709__auto__))
  34. (clojure.core/defn
  35. to-cm
  36. [m__32709__auto__]
  37. (clojure.core/* 100 m__32709__auto__))
  38. (clojure.core/defn
  39. to-km
  40. [m__32709__auto__]
  41. (clojure.core/* 1/1000 m__32709__auto__)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement