This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How is (children) supposed to work?


Nic Ferrier wrote:
> I'm a bit confused by the details of TreeList. There doesn't seem
> to be any easy way (from Scheme or Java) to traverse what's in a tree.
> 
> I thought that the doing:
> 
>  (children some-tree-list)
> 
> would return the children of a TreeList

Seems to work:

#|kawa:1|# (children (make-element 'aa (make-element 'bb) "XX"))
(bb)XX
#|kawa:2|# (define xx (make-element 'aa (make-element 'bb) "XX"))
#|kawa:3|# xx
(aa(bb)XX)
#|kawa:4|# (children xx)
(bb)XX

On the other hand:

#|kawa:5|# (define yy (children xx))
#|kawa:6|# yy
{gnu.lists.TreeList@5122060 ipos: 6 xpos: 
null}{gnu.lists.TreeList@5122060 ipos: 16 xpos: 
null}{gnu.lists.TreeList@5122060 ipos: 18 xpos: null}

In this case you get actually get a SeqPosition for each
child, rather than having the child's *contents* be printed.
This should probably be made more consistent

 > but instead it needs to consume the children of a TreeList.

Yes.  Consumer is used to return multiple values and generally
pass data "by value" (as opposed to "by reference").

It's not as consistent, solid, efficient, or documented as it
should be.  However, using a Consumer, is part of the API of many
Proceduers.  This makes the Java interface perhaps a little
ugly, but most things automatically work right at the Scheme
or XQuery level.

Note also a SeqPosition that points into a TreeList is the Kawa
version of a DOM node.  However, SeqPosition is also used to
iterate over TreeLists as well as Sequences,  It is not as
solid as it should be when a function is allowed to change a
SeqPosition, but at least in the context fo XQuery it works
pretty well.

> I'm just not clear about what is going on at all, I tried doing this:
> 
>   URL u = new URL("file:/home/nferrier/web.xml");
>   TreeList t = ParsedXMLToConsumer.parse(u);
>   ListIterator l = t.listIterator();
>   System.out.println(l.next());
> 
> But after a few next() calls the thing hangs. I'm not sure why.

I'm not sure either.  However, using ListIterators has not
been well tested, and it is not clear what it should do.  Technically,
TreeList isn't a Sequence, though it does inherit from AbstractSequence.

Why a TreeList isn't a Sequence has to do with the difference between
a sequence and "multiple values" (in the call-with-values send).
A normal TreeList only has a single value, assuming it has a single
document node, so ListIterator doesn't make any sense.  (Note that
Values is now implemented as a sub-class of TreeList.  "Multiple
values" is a TreeList with multiple root in the TreeList.)
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]