Skip to content

Instantly share code, notes, and snippets.

(defn f1 [n]
(lazy-seq
(cons n (f1 (inc n)))))
(nth (f1 0) 5000)
;; => 5000
(defn f2 [n]
(lazy-seq
(cons n (map identity (f2 (inc n))))))
; Currencies know how to create Money
(defprotocol Currency
(make-money [this amount]))
; Money knows the details about how to print itself, round, etc.
; We want to be able to pass Moneys around, and after the fact, be able to
; print them, round them, etc.
(defprotocol Money
(str$ [this])
(round$ [this]))
@paraseba
paraseba / gist:1328334
Created October 31, 2011 18:21
Setup your environment for the Clojure hands-on training

##Install Java

Install any version of Java JDK >= 1.5 You can download Java using your system's package manager or going to http://www.oracle.com/technetwork/java/javase/downloads/index.html

##Install Leiningen

Leiningen will help us automating some common tasks like installing dependencies and running the REPL. The installation procedure changes if you are in a Unix like system or in Windows. If you have any problems, there is more information in Leiningen's page: https://github.com/technomancy/leiningen

(def file-path "words.txt")
@paraseba
paraseba / gist:1167254
Created August 24, 2011 03:40
Jorge Luis Borges on novice writers (or programmers?)
Look, I mean to say this: When I began writing, I thought that
everything should be defined by the writer. For example, to say
“the moon” was strictly forbidden; that one had to find an
adjective, an epithet for the moon. (Of course, I'm simplifying
things. I know it because many times I have written “la luna,”
but this is a kind of symbol of what I was doing.) Well, I
thought everything had to be defined and that no common turns
of phrase should be used. I would never have said, “So-and-so
came in and sat down,” because that was far too simple and far
too easy. I thought I had to find out some fancy way of saying
(defn checkout-deps-paths [project]
(apply concat (for [dep (.listFiles (file (:root project) "checkouts"))
;; Note that this resets the leiningen.core/project var!
:let [proj (read-dependency-project dep)]
:when proj]
(for [d (:checkout-deps-shares project [:source-path :compile-path :resources-path])]
(ensure-absolute (d proj) dep))))))
:checkout-deps-shares [:source-path :resources-path :test-path