dimanche 1 juin 2014

How to make list of partial functions in Clojure?


Vote count:

0




i need to write code like this in clojure.



-- haskell
fns = map (,) [1..3]
head fns $ 1
-- => (1,1)
fns <*> [1..3]
-- => [(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)]


doesn't work



(def fns (map (partial list) (range 1 3)))
((first fns) 1)
;; => ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn


works, but i think this isn't idiomatic way



(def fns (map (fn [x] `(partial list ~x)) (range 1 3)))
((eval (first fns)) 1)
;; => (1 1)


asked 44 secs ago






Aucun commentaire:

Enregistrer un commentaire