Skip to content

Instantly share code, notes, and snippets.

@xixixao
Created April 3, 2013 08:59
Show Gist options
  • Save xixixao/5299596 to your computer and use it in GitHub Desktop.
Save xixixao/5299596 to your computer and use it in GitHub Desktop.
Clojure vs Coffee
#(defn parting
# "returns a String parting in a given language"
# ([] (parting "World"))
# ([name] (parting name "en"))
# ([name language]
# (condp = language
# "en" (str "Goodbye, " name)
# "es" (str "Adios, " name)
# (throw (IllegalArgumentException.
# (str "unsupported language " language))))))
#
#(println (parting)) ; -> Goodbye, World
#(println (parting "Mark")) ; -> Goodbye, Mark
#(println (parting "Mark" "es")) ; -> Adios, Mark
#(println (parting "Mark", "xy")) ; -> java.lang.IllegalArgumentException: unsupported language xy
parting = (name = "World", language = "en") ->
switch language
when "en" then "Goodbye, #{name}"
when "es" then "Adios, #{name}"
else throw "unsupported language #{language}"
log parting()
log parting "Mark"
log parting "Mark", "es"
log parting "Mark", "xy"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment