On Fri, Jan 23, 2009 at 4:13 PM, Mark Volkmann
<[email protected]> 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")))

--Chouser

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