On Fri, Jan 23, 2009 at 3:43 PM, Chouser <chou...@gmail.com> wrote:
>
> On Fri, Jan 23, 2009 at 4:13 PM, Mark Volkmann
> <r.mark.volkm...@gmail.com> wrote:
>>
>> I'm trying to implement pig latin using only what's in core in the
>> simplest way possible.
>> Does anyone see a simpler way?
>> I'm not happy with using three functions (some, set and str) to
>> determine if a letter is a vowel.
>
> I'm not quite sure what your criteria is, but here are a couple other options:
>
> ; String.contains and an extra 'subs'
> (defn pig-latin [word]
>  (let [first-letter (subs word 0 1)]
>    (if (.contains "aeiou" first-letter)
>      (str word "ay")
>      (str (subs word 1) first-letter "ay"))))
>
> ; String.contains with destructuring
> (defn pig-latin [[first-letter :as word]]
>  (if (.contains "aeiou" (str first-letter))
>    (str word "ay")
>    (str (subs word 1) first-letter "ay")))
>
> ; Strings collapse quivering in fear when destructuring and regex join forces
> (defn pig-latin [word]
>  (if-let [[_ a b] (re-find #"^([^aeiou])(.*)" word)]
>    (str b a "ay")
>    (str word "ay")))

Thanks! I like the second option the best.
I hope option three was written to be funny. I both laugh and cry when
looking at that. ;-)

-- 
R. Mark Volkmann
Object Computing, Inc.

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