(fn [n] :new) or (constantly :new) was what I was looking for. Just found out the two are not exactly the same. Hmm. I guess I should have expected this from the docstring. Anyway, thanks all!
Clojure=> (map (constantly (ref nil)) (range 10)) 50 (#<Ref clojure.lang....@1417690> #<Ref clojure.lang....@1417690> #<Ref clojure.lang....@1417690> #<Ref clojure.lang....@1417690> #<Ref clojure.lang....@1 417690> #<Ref clojure.lang....@1417690> #<Ref clojure.lang....@1417690> #<Ref clojure.lang....@1417690> #<Ref clojure.lang....@1417690> #<Ref clojure.lan g....@1417690>) 51 Clojure=> (map (fn [n] (ref nil)) (range 10)) 52 (#<Ref clojure.lang....@1e32382> #<Ref clojure.lang....@1304043> #<Ref clojure.lang....@cb07ef> #<Ref clojure.lang....@176086d> #<Ref clojure.lang....@23 4265> #<Ref clojure.lang....@dc1f04> #<Ref clojure.lang....@1784427> #<Ref clojure.lang....@c272bc> #<Ref clojure.lang....@1fac852> #<Ref clojure.lang.Re f...@1758cd1>) On Apr 16, 11:54 am, David Sletten <da...@bosatsu.net> wrote: > On Apr 15, 2009, at 11:30 PM, bOR_ wrote: > > > > > Hi all, > > > some functions (like map, or update-in) expect a function to be > > applied on a value. In the case where the update I want is merely a > > constant, is there a short way to write it? > > > (map (fn [n] :new) (list :old1 :old2 :old3)) works > > > (map :new (list :old1 :old2 :old3)) unfortunately doesn't work in the > > way I would hope (gives nil nil nil) > > There are a number of possible answers here depending on what you're > trying to do. The one that corresponds literally to your approach is > this: > (map (constantly :new) (list :old1 :old2 :old3)) > 'constantly' creates a function which simply ignores its arguments > and returns the value provided. > > But if all you are really doing is creating a sequence of a given > length containing a constant element, then this is more straightforward: > (repeat (count (list :old1 :old2 :old3)) :new) > > Aloha, > David Sletten --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---