Created
November 2, 2011 03:22
-
-
Save mikera/1332761 to your computer and use it in GitHub Desktop.
Cool Clojure examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Frequency analysis (implicitly treating a string as a sequence of chars) | |
(frequencies "abracadabra") | |
=> {\a 5, \b 2, \r 2, \c 1, \d 1} | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Infinite, lazily calculated sequence of Fibonacci numbers | |
(def fibs | |
(lazy-cat [0N 1N] (map + (rest fibs) fibs))) | |
(take 10 fibs) | |
=> (0 1 1 2 3 5 8 13 21 34) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment