What is the Clojure best practice, if there is one, for writing a
function like this:
pre
(defn integral [integrand initial-value dt]
(def --integral (cons initial-value
(lazy-seq (add-streams (scale-
streams integrand dt)
--integral
--integral)
/pre
Use let:
(defn foo [...]
(let [helper (fn [...] ...)]
(helper ...)))
or letfn:
(defn foo [...]
(letfn [(helper [...] ...)]
(helper ...)))
The latter allows you to introduce mutually recursive functions.
Sincerely,
Michał
--
You received this message because you are subscribed to
don't use def inside functions, ever. in scheme define is lexically scoped,
so you do that sort of thing. clojure is not scheme. if you want a lexically
scoped function use a lexical scoping construct like let or letfn.
On Mon, Feb 8, 2010 at 12:12 PM, Brenton bashw...@gmail.com wrote:
What is
letfn is exactly what I was looking for.
Thank you.
On Feb 8, 12:15 pm, Michał Marczyk michal.marc...@gmail.com wrote:
Use let:
(defn foo [...]
(let [helper (fn [...] ...)]
(helper ...)))
or letfn:
(defn foo [...]
(letfn [(helper [...] ...)]
(helper ...)))
The latter