Upcoming SlideShare
×

# Clojure functions

371 views
340 views

Published on

Some clojure function examples

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
371
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
3
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Clojure functions

1. 1. Clojure Example Functions ilegra - LDCBy Jackson dos Santos
2. 2. loop(defn decCount[n m] (loop [i n] (if (> i m) (recur (dec i)) i ) ))(println (decCount 8 4))
3. 3. 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"))
4. 4. 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 "******************************")
5. 5. 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))