You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
794 B
Clojure
19 lines
794 B
Clojure
(defn parting
|
|
"returns a String parting in a given language"
|
|
([] (parting "World"))
|
|
([name] (parting name "en"))
|
|
([name language]
|
|
; condp is similar to a case statement in other languages.
|
|
; It is described in more detail later.
|
|
; It is used here to take different actions based on whether the
|
|
; parameter "language" is set to "en", "es" or something else.
|
|
(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 |