I wonder if the somewhat counterintuitive concept of a named anonymous
function eludes some people, or isn't properly conveyed in tutorials.
On Tuesday, 27 August 2013 00:36:07 UTC-7, HamsterofDeath wrote:
thx
2013/8/26 Marshall Bockrath-Vandegrift lla...@gmail.com javascript:
Dennis
On 29/08/13 20:23, JvJ wrote:
I wonder if the somewhat counterintuitive concept of a named
anonymous function eludes some people, or isn't properly conveyed in
tutorials.
I only consider #(...) as an anonymous function. The longer form (fn []
(...)) has the potential of being perfectly
This exact use case is covered by letfn, which creates a named fn
accessible to all function definitions and the body. That even allows
mutual recursive definitions without declare. Your example would be
(defn fib-n [n]
(letfn [(fib [a b]
(cons a (lazy-seq (fib b (+ b
thx again
2013/8/30 Bruno Kim Medeiros Cesar brunokim...@gmail.com
This exact use case is covered by letfn, which creates a named fn
accessible to all function definitions and the body. That even allows
mutual recursive definitions without declare. Your example would be
(defn fib-n [n]
thx
2013/8/26 Marshall Bockrath-Vandegrift llas...@gmail.com
Dennis Haupt d.haup...@gmail.com writes:
(defn fib-n [n]
(let [fib (fn [a b] (cons a (lazy-seq (fib b (+ b a)]
(take n (fib 1 1
can't i do a recursion here? how can i achieve this without doing an
outer defn?
(defn fib-n [n]
(let [fib (fn [a b] (cons a (lazy-seq (fib b (+ b a)]
(take n (fib 1 1
can't i do a recursion here? how can i achieve this without doing an outer
defn?
--
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this
Dennis Haupt d.haup...@gmail.com writes:
(defn fib-n [n]
(let [fib (fn [a b] (cons a (lazy-seq (fib b (+ b a)]
(take n (fib 1 1
can't i do a recursion here? how can i achieve this without doing an
outer defn?
You just need to give the anonymous function a name it can use to refer
If you want the sequence itself, so you can take various prefixes of it:
(def fib (cons 1 (cons 1 (map + fib (rest fib)
(take 5 fib)
(take 10 fib)
Has the advantage of not recalculating any part of it - and the
disadvantage of holding onto the head - so it depends what you want to
do with