Am Donnerstag, 15. September 2011 schrieb Ken Wesson :
> On Thu, Sep 15, 2011 at 8:56 AM, Herwig Hochleitner
> > wrote:
> > Consider
> >
> > (defn find-in-tree
> > ([tree pred?]
> >(concat
> > (filter pred? tree)
> > (mapcat find-in-tree (filter sequential? tree) (repeat pred?)
Thanks for clarifying the stack space issue. I got confused with the
original implementation, and was unsure it would run with a large sequence.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups
On Thu, Sep 15, 2011 at 8:56 AM, Herwig Hochleitner
wrote:
> Consider
>
> (defn find-in-tree
> ([tree pred?]
> (concat
> (filter pred? tree)
> (mapcat find-in-tree (filter sequential? tree) (repeat pred?)
>
> which of course is much simpler written as
>
> (defn find-in-tree
> ([
On Thu, Sep 15, 2011 at 8:56 AM, Herwig Hochleitner
wrote:
> Hi,
>
> as you might know, the original version actually does run in fixed
> stack space, thanks to lazy sequences.
You are right!
Without testing it I had thought that the way recursion was used would
cause skl to overflow the stack i
Hi,
as you might know, the original version actually does run in fixed
stack space, thanks to lazy sequences.
(defn skl
[tree]
(map skl (filter seq? tree)))
loop .. recur is the moral equivalent of a while(true) loop in
imperative style. i.e. a slightly disguised (and somewhat more
structure
On Wed, Sep 14, 2011 at 3:58 PM, octopusgrabbus
wrote:
> Alan:
>
> I may have misunderstood what I've read both in books, blogs, and the
> Clojure site, but it seems that writing recursive functions in the loop ..
> recur style is the preferred style. I also remember most of the texts
> currently
Hi,
2011/9/14 Alan Malloy
> You can prefer anything you want, but (a) to say that Clojure prefers
> loop/recur is nonsense, and (b) you can't make an incorrect algorithm
> work just by preferring it. Jeff is correct that your algorithm
> requires space for each level of the tree, and so cannot b
2011/9/14 Meikel Brandmeyer
> Hi,
>
> Am 14.09.2011 um 16:54 schrieb octopusgrabbus:
>
> > (defn skl
> > [tree]
> > (map skl (filter seq? tree)))
> >
>
> Is that what you want?
>
> (defn skl
> [tree]
> (loop [output []
> tree (seq tree)]
>(if tree
> (let [fst (first tree)
Alan:
I may have misunderstood what I've read both in books, blogs, and the
Clojure site, but it seems that writing recursive functions in the loop ..
recur style is the preferred style. I also remember most of the texts
currently out on Clojure say use the higher level sequence functions rath
Thanks. I'll have a look.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this
You can prefer anything you want, but (a) to say that Clojure prefers
loop/recur is nonsense, and (b) you can't make an incorrect algorithm
work just by preferring it. Jeff is correct that your algorithm
requires space for each level of the tree, and so cannot be converted
into a constant-space alg
Hi,
Am 14.09.2011 um 16:54 schrieb octopusgrabbus:
> (defn skl
> [tree]
> (map skl (filter seq? tree)))
>
Is that what you want?
(defn skl
[tree]
(loop [output []
tree (seq tree)]
(if tree
(let [fst (first tree)]
(if (seq? fst)
(recur (conj output
Jeff:
loop .. recur syntax is Clojure's preferred method of recursion.
This is a routine to return the skeleton of a sequence, not its values.
cmn
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegr
In general, you can't convert recursion into loops. Recursion has
stack frames, loops don't.
I can't really tell what you are trying to do here because your
example just walks the interior nodes of the expression tree, doing
nothing. Can you clarify with a more complete example?
--
You received
14 matches
Mail list logo