clojure functions
DESCRIPTION
Some clojure function examplesTRANSCRIPT
Clojure Example Functions
ilegra - LDCBy Jackson dos Santos
loop
(defn decCount[n m]
(loop [i n]
(if (> i m)
(recur (dec i))
i
)
)
)
(println (decCount 8 4))
If-not
(defstruct softwareDesigner :name :preferredOs)
(def designer (struct softwareDesigner "Jeferson" "MAC OS"))
(if-not (= :preferredOs designer "MAC OS")
(println "The software designer" :name designer " is fag")
(println "The Software Designer " :name designer " is man")
)
identical
(defstruct pokemon :name :powerLevel)
(println "**** Ther first objects pair *****")
(def firstPokemon (struct pokemon "Pikachu" "Low"))
(def secondPokemon (struct pokemon "Blastoise" "High"))
(println (:name :powerLevel firstPokemon))
(println (:name :powerLevel secondPokemon))
(println "Are they identical?" (identical? firstPokemon secondPokemon))
(println "******************************")
(println "**** Ther second objects pair *****")
(def firstPokemon (struct pokemon "Blastoise" "High"))
(def secondPokemon (struct pokemon "Blastoise" "High"))
(println (:name :powerLevel firstPokemon))
(println (:name :powerLevel secondPokemon))
(println "Are they identical?" (identical? firstPokemon firstPokemon))
(println "******************************")
Calculator implementation
(defn calc[operator digit1 digit2]
(cond (= 0 (compare "+" operator)) (+ digit1 digit2)
(= 0 (compare "-" operator)) (- digit1 digit2)
(= 0 (compare "*" operator)) (* digit1 digit2)
(= 0 (compare "/" operator)) (/ digit1 digit2)
)
)
(println (calc "+" 4 5))
(println (calc "-" 5 1))
(println (calc "*" 2 3))
(println (calc "/" 27 3))