Re: too circular?

2013-08-29 Thread JvJ
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

Re: too circular?

2013-08-29 Thread Jim - FooBar();
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

Re: too circular?

2013-08-29 Thread Bruno Kim Medeiros Cesar
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

Re: too circular?

2013-08-29 Thread Dennis Haupt
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]

Re: too circular?

2013-08-27 Thread Dennis Haupt
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?

too circular?

2013-08-26 Thread Dennis Haupt
(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

Re: too circular?

2013-08-26 Thread Marshall Bockrath-Vandegrift
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

Re: too circular?

2013-08-26 Thread Sean Corfield
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