Clojure functions
Upcoming SlideShare
Loading in...5
×
 

Clojure functions

on

  • 367 views

Some clojure function examples

Some clojure function examples

Statistics

Views

Total Views
367
Views on SlideShare
367
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Clojure functions Clojure functions Presentation Transcript

  • 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))