Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn twice
- "make the number twice as large, have an ugly side effect of println, return it"
- [x]
- (println (str "Doubling the value of " x))
- (* 2 x))
- (defn do-stuff
- "this is how i define a function in clojure"
- [limit]
- (let [all-numbers-starting-from-zero (range)
- to-the-limit (take limit all-numbers-starting-from-zero)
- multiplied-by-two (map twice to-the-limit)]
- (println (str "Input numbers " (clojure.string/join "," to-the-limit)))
- (println (str "Smallest of twiced " (apply min multiplied-by-two)))
- (println (str "Biggest of twiced " (apply max multiplied-by-two)))
- (println (str "Sum of twiced " (reduce + multiplied-by-two)))
- ))
- (defn -main
- "I don't do a whole lot ... yet."
- [& args]
- (do-stuff 5))
- ;; Output of the code above
- ; Input numbers 0,1,2,3,4
- ; Doubling the value of 0
- ; Doubling the value of 1
- ; Doubling the value of 2
- ; Doubling the value of 3
- ; Doubling the value of 4
- ; Smallest of twiced 0
- ; Biggest of twiced 8
- ; Sum of twiced 20
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement