Skip to content

Instantly share code, notes, and snippets.

@mikera
Created November 2, 2011 03:22
Show Gist options
  • Save mikera/1332761 to your computer and use it in GitHub Desktop.
Save mikera/1332761 to your computer and use it in GitHub Desktop.
Cool Clojure examples
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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