I am not particularly fond of idiomatic style. In production code I
want something clear and explicit even if it is a bit longer. That
said, your question triggered this challenge: What's the shortest way
for capitalizing the first letter of every word, i.e.: (assert (=
(capitalize "ab cd") "Ab Cd")) ?

Here's my take:

(defn capitalize [s]
  (apply str (map (fn [prev curr]
    (or (and (= prev \space) (Character/toUpperCase curr)) curr))
    (cons \space s) s)))


--
Itay Maman
http://javadots.blogspot.com

On Mar 8, 3:20 pm, David Sletten <[email protected]> wrote:
> On Mar 8, 2009, at 2:45 AM, Joshua Fox wrote:
>
>
>
> > How about this?
> > user=> (defn upper-first [s] (apply str (Character/toUpperCase (first
> > s)) (rest s)))
> > #'user/upper-first
> > user=> (upper-first "aaaaa")
> > "Aaaaa"
>
> That certainly qualifies as less idiotic. :)
>
> Mahalo,
> David Sletten
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to