Created
April 3, 2013 08:59
-
-
Save xixixao/5299596 to your computer and use it in GitHub Desktop.
Clojure vs Coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#(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