Re: clojure.zip/goto proposal

2008-10-18 Thread Meikel Brandmeyer

Hi,

Am 16.10.2008 um 23:07 schrieb Meikel Brandmeyer:


I'll will mull a bit more about this. But something along the lines
of (goto loc some-predicate path) seems like it could do what it want.


Ok. The attached patch is what I came up with. It is actually
split up in two functions walk-along-and-do and walk-along.
(Naming suggestions welcome).

So the idea is: I give it a location in the zipper, a predicate
to identify the nodes and path, which is basically a sequence of
things. (pred node thing) should identify the desired node however.

Using this I successfully implemented a two-tree widget in Swing,
where selected nodes are moved between the two widgets inserting
dependent structure as necessary.

Here I also saw the need of a try-walk-along, which returns the
last node of the path, which is contained in the tree and the
rest of the path, which is missing. So I extracted the walker
code and added two callbacks, a found-action and a not-found-action.
In the current implementation it only finds the left-most path in
a tree, in case the nodes are not unique.

The difference to your XML code is, that xml- allows a different
filter for each step. This is not the case here.

Sincerely
Meikel



walk-along.clj
Description: Binary data




smime.p7s
Description: S/MIME cryptographic signature


Re: clojure.zip/goto proposal

2008-10-16 Thread Chouser

On Thu, Oct 16, 2008 at 10:42 AM, mb [EMAIL PROTECTED] wrote:

 I'd like to propose a clojure.zip/goto function. It is basically
 the inverse of the clojure.zip/path function, ie. it takes a
 location and a path and walks through the zipper to the
 given node and returns its loc.

Wouldn't each step of the path have to provide the entire sub-tree at
that point, in order for = to return true?  How would this be useful?
Or am I misunderstanding something?

--Chouser

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure.zip/goto proposal

2008-10-16 Thread Meikel Brandmeyer

Hello,

Am 16.10.2008 um 16:56 schrieb Chouser:

 I'd like to propose a clojure.zip/goto function. It is basically
 the inverse of the clojure.zip/path function, ie. it takes a
 location and a path and walks through the zipper to the given
 node and returns its loc.

Wouldn't each step of the path have to provide the entire sub-tree
at that point, in order for = to return true?  How would this be
useful?  Or am I misunderstanding something?


Ok. I see your point. I have to check the whole sub-tree to see
whether they are equal. So = was maybe a bit naive.

But then I don't see use of zip. Given an arbitrary node in a tree.
How do I go there? Yes, I can navigate left and right and up and
down. But how do I know, that I'm there, if I can't compare the
current node to the one I'm looking for?

So I need some external way of navigation. Maybe one can also
provide a function how to compare nodes. ad-hoc trees like
[1 [2 3] [[[4 5] 6] 7 8]] then only have identical? as a predicate,
which does not compare the whole tree. But for example a tree
representing some files doesn't need the whole node, but only a
label. /usr/bin/clojure. Three labels: usr, bin and clojure.
Together with the way they are composed they identify the node.
(Skipping the root node for some moment...)

(- fs-tree-zip
(goto [usr bin clojure])
(edit rename clj)
root)

Giving an self-defined predicate would make this possible.

(zip/zipper (branch...) (children...) (make-node...)
(fn [node needle] (= (. node fileName) needle))
fs-root)

Or maybe a goto-by: (goto-by loc predicate path)?

I think the idea of the zipper is really awesome. It would be
exactly what I need, since it takes care of also reconstructing
the tree after editing it. But honestly I see a problem on how to
get to the actual place, where the editing should happen

If there are some examples of zipper use, please point me there.

Sincerely
Meikel




smime.p7s
Description: S/MIME cryptographic signature


Re: clojure.zip/goto proposal

2008-10-16 Thread Chouser

On Thu, Oct 16, 2008 at 2:10 PM, Meikel Brandmeyer [EMAIL PROTECTED] wrote:

 So I need some external way of navigation. Maybe one can also
 provide a function how to compare nodes. ad-hoc trees like
 [1 [2 3] [[[4 5] 6] 7 8]] then only have identical? as a predicate,
 which does not compare the whole tree. But for example a tree
 representing some files doesn't need the whole node, but only a
 label. /usr/bin/clojure. Three labels: usr, bin and clojure.
 Together with the way they are composed they identify the node.

Ok, we're on the same page here.  I think the only problem with your
original example was that since a node contains all of its
descendants, = isn't a terribly useful way to navigate.  As you
suggest, you want some kind of selector to pick out the bits you
actually want to use in navigation, filename or whatever.  Perhaps
you could simply pass in a filter function to your original goto, to
allow partial application-specific comparisons.

I've already done some work for navigation of zip-xml trees -- see
clojure.contrib.zip-filter.xml

I'm not sure how zip-seq trees would be used and if there's anything
from clojure.contrib.zip-filter that would be useful for navigating
those.

--Chouser

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: clojure.zip/goto proposal

2008-10-16 Thread Meikel Brandmeyer

Hi,

Am 16.10.2008 um 20:20 schrieb Chouser:


actually want to use in navigation, filename or whatever.  Perhaps
you could simply pass in a filter function to your original goto, to
allow partial application-specific comparisons.

I had a look in clojure.contrib.zip-filter.xml. I think it works
a bit different, but similar. %) It is different because their
might be several nodes with the same tag name on the same level.
So you return all those nodes. I'm mostly interested in trees, where
the children of a node are unique.


I'm not sure how zip-seq trees would be used and if there's anything
from clojure.contrib.zip-filter that would be useful for navigating
those.

There each node is defined by its children. So one can only select on
subset. Eg. the first child is the directory name and the rest the
filenames. But this would be only convention. Other than that there
would be only identical? as a short-cut comparison...

I'll will mull a bit more about this. But something along the lines
of (goto loc some-predicate path) seems like it could do what it want.

Sincerely
Meikel




smime.p7s
Description: S/MIME cryptographic signature