Re: pl-iterator
Thomas Russ <[email protected]> Fri, 2 Nov 2007 09:19:13 -0700
| Newsgroups | gmane.comp.ai.powerloom |
|---|---|
| Message-ID | <[email protected]> |
On Nov 1, 2007, at 6:11 PM, Magnus Malm wrote:
> Hello
>
> How does the pl-iterator work in the common lisp api? I can't seem
> to find any info about this in the docs or the sources.
It works like a standard Stella iterator. I guess I should make sure
we have this documented somewhere.
Anyway, the Stella iterator API works like this. There is a test for
whether elements remain in the iterator, called "next?" [Lisp:
stella::next?(), C++/Java: nextP()] that advances the iterator and
reports whether there is an element present or not. A fresh iterator
does not yet point to the first element, so it is safe (and required)
to call next? before accessing elements. The value is extracted
using "value" [Lisp: stella::%value, C++/Java value], which can be
safely read as often as one wishes.
Summary:
next? Advances iterator and reports if a new value exists
value Gets the current value. This is an instance variable
or field.
Sample Common Lisp usage:
(LET* ((ITER (PLI:S-RETRIEVE "all (concept ?c)" STELLA::NULL-STRING
NULL)))
(LOOP WHILE (STELLA::NEXT? ITER) DO
(PRINT (STELLA::%VALUE ITER))))
[Unfortunately, the Stella functions are not exported from the
package. PLI functions are.]
Sample C++ usage:
{ pli::PlIterator* iter = pli::sRetrieve("all (concept ?c)", NULL,
NULL);
while (iter->nextP()) {
std::cout << iter->value << std::eol;
}
}
Sample Java usage:
use edu.isi.powerloom.*;
{ PlIterator iter = PLI.sRetrieve("all (concept ?c)", null, null);
while (iter.nextP()) {
System.out.println(iter.value);
}
}
You would then use the PowerLoom API functions "get-nth-..." to work
with the values or tuples returned by the iterator.