Re: A useful function?

2010-08-17 Thread Alan
If you say so. I mean, I see that your example produces output different than I might expect, but that's a function of clojure's basic API - memoize will do the same thing: user (def q (atom 1)) #'user/q user (defn myinc [ignored] (swap! q inc)) #'user/myinc user (def m (memoize myinc)) #'user/m

Re: A useful function?

2010-08-17 Thread Alan
Double-posting myself, here, just to join the fun. You can generalize if you don't always want the same behavior: user (defn apply-by [glue] (fn [f keys] (glue keys (map f keys #'user/apply-by user ((apply-by zipmap) inc (range 5)) {4 5, 3 4, 2 3, 1 2, 0 1} user

A useful function?

2010-08-16 Thread Alan
(defn apply-keys [f ks] (zipmap ks (map f ks))) Trivial to write, but it can be quite useful. For example: (defn whatever [arg] (let [some-list (make-list-from arg) mapped (map myfunc some-list)] (zipmap some-list mapped))) compared to (defn whatever [arg] (apply-keys myfunc

Re: A useful function?

2010-08-16 Thread Saul Hazledine
On Aug 16, 8:31 am, Alan a...@malloys.org wrote: (defn apply-keys [f ks]   (zipmap ks (map f ks))) Does this seem useful to anyone else? It seems very similar to memoize in that you're mapping function arguments to their results. Saul -- You received this message because you are subscribed

Re: A useful function?

2010-08-16 Thread Chang Min Jeon
hello alan. This link may help you. http://richhickey.github.com/clojure-contrib/index.html BR ChangMin Jeon On Mon, Aug 16, 2010 at 4:31 PM, Alan a...@malloys.org wrote: (defn apply-keys [f ks] (zipmap ks (map f ks))) Trivial to write, but it can be quite useful. For example: (defn

Re: A useful function?

2010-08-16 Thread wwmorgan
Sorry for the double-post. group-by actually maps outputs to inputs. But you can run into trouble even with referentially transparent functions, because of Clojure's equality semantics: user= (def x [(list :a) (vector :a)]) #'user/x user= (zipmap x (map class x)) {(:a)

Re: A useful function?

2010-08-16 Thread Sean Devlin
This comes up on the list every few months. In Clojure, this is a code smell that you should be using the destructuring constructs instead. On Aug 16, 3:31 am, Alan a...@malloys.org wrote: (defn apply-keys [f ks]   (zipmap ks (map f ks))) Trivial to write, but it can be quite useful. For