[ library(m_tree234) | Reference Manual | Alphabetic Index ]

iter_next(+Iter1, -Key, -Value, -Iter2)

Retrieve the next tree entry using an iterator
Iter1
A tree iterator
Key
A retrieved key
Value
The retrieved value corresponding to Key
Iter2
An updated tree iterator (output)

Description

Retrieve the next Key-Value entry from the tree position indicated by the iterator, and return a new iterator for the next entry.

If the retrieved entry is the last one, Iter2 is the empty iterator []. The end of iteration can be determined either by testing the iterator for being [], or by the failure of iter_next when called with an empty iterator.

Fail Conditions

Iter1 is the empty iterator ([])

Examples

        % Print all tree entries using recursion:
        print_tree(Tree) :-
            iter_init(Tree, It),
            print_it(It).

        print_it(It1) :-
            ( iter_next(It1, K, V, It2) ->
                writeln(K-V),
                print_it(It2)
            ;
                true
            ).

        % The same using a do-loop:
        print_tree(Tree) :-
            iter_init(Tree, It0),
            ( fromto(It0,It1,It2,[]) do
                iter_next(It1, K, V, It2),
                writeln(K-V)
            ).
        

See Also

iter_init / 2, member / 3