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
-~----------~----~----~----~------~----~------~--~---

Reply via email to