Why isn't a zipper appropriate for tree recursion?
On Sunday, December 8, 2013 2:16:33 AM UTC, Alexander Hudek wrote:
>
> This is still just recursion because of the map. That means it has all the
> problems of recursion. If you need to avoid recursion, you need to do a
> depth first or breadth
This is still just recursion because of the map. That means it has all the
problems of recursion. If you need to avoid recursion, you need to do a
depth first or breadth first traversal of the tree and hold onto state as
you do it. The zipper does some of this for you and provides an easy way to
Thanks I'll take a look at your libraries.
One problem I found with the zipper API is that if you have a recursive
function that takes a loc, when you call it on the clojure.zip/children of
a given loc it won't work because this function returns a seq of nodes
instead of a seq of locs. Shouldn'
Additionally, if you need more complex access patterns you could see if
this helps:
https://github.com/akhudek/zip-visit
For performance, there is a fast-zip library that is api compatible with
clojure.zip. You can just swap the clojure.zip namespace for the fast-zip
namespace. Note that you'd
On 4 December 2013 21:09, dabd wrote:
> I didn't get there because I ran into problems with the zipper API. When
> you call 'children' on a loc you get a seq of nodes instead of a seq of
> locs which causes me problems in a recursive algorithm operating on locs.
>
Have you tried using next and
oh, I meant custom from the bottom up, without using clojure.zip at all (so
your issue with the return value of children wouldn't come up). I realize
this doesn't answer your question about alternatives.
On Wed, Dec 4, 2013 at 1:15 PM, dabd wrote:
> I had to implement a custom tree zipper as no
I had to implement a custom tree zipper as none of the existing zippers
worked for me.
My question is are there better alternatives when you want the best
performance in clojure?
On Wednesday, December 4, 2013 9:12:16 PM UTC, Ben wrote:
>
> it might be worthwhile to implement custom zippers for
it might be worthwhile to implement custom zippers for your trees, without
using clojure.zip. I've done this for navigating into json structures and
it was relatively painless (admittedly I only needed a smallish subset of
the functionality provided by clojure.zip).
On Wed, Dec 4, 2013 at 1:09 PM
I didn't get there because I ran into problems with the zipper API. When
you call 'children' on a loc you get a seq of nodes instead of a seq of
locs which causes me problems in a recursive algorithm operating on locs.
On Wednesday, December 4, 2013 8:38:17 PM UTC, James Reeves wrote:
>
> On 4
On 4 December 2013 20:27, dabd wrote:
>
> I tried a purely functional approach with zippers but ran into some
> trouble with the zipper API. I also think I will would have performance
> problems too as there is a lot of bookkeeping in a zipper (paths, parents
> associated with a loc).
>
You thin
I go for an imperative implementation it seems like deftype to represent
the tree nodes would work well since it allows for mutable fields.
Any advice on choosing the right data structure and whether to use
a functional or imperative implementation is appreciated.
Thanks.
--
--
You received
11 matches
Mail list logo