A simple iterator facility is provided to allow, for example, iterating over the set of program symbols without having to first construct a list of all of them. A useful contribution would be to add support for SRFI 41 and SRFI 45.
<gdb:iterator> object is constructed with the
procedure. It takes three arguments: the object to be iterated over,
an object to record the progress of the iteration, and a procedure to
return the next element in the iteration, or an implementation chosen value
to denote the end of iteration.
By convention, end of iteration is marked with
and may be tested with the
The result of
(end-of-iteration) is chosen so that it is not
otherwise used by the
(gdb) module. If you are using
<gdb:iterator> in your own code it is your responsibility to
maintain this invariant.
A trivial example for illustration’s sake:
(use-modules (gdb iterator)) (define my-list (list 1 2 3)) (define iter (make-iterator my-list my-list (lambda (iter) (let ((l (iterator-progress iter))) (if (eq? l '()) (end-of-iteration) (begin (set-iterator-progress! iter (cdr l)) (car l)))))))
Here is a slightly more realistic example, which computes a list of all the
(use-modules (gdb iterator)) (define this-sal (find-pc-line (frame-pc (selected-frame)))) (define this-symtab (sal-symtab this-sal)) (define this-global-block (symtab-global-block this-symtab)) (define syms-iter (make-block-symbols-iterator this-global-block)) (define functions (iterator-filter symbol-function? syms-iter))
#t if object is a
Return the first argument that was passed to
This is the object being iterated over.
Return the object tracking iteration progress.
Set the object tracking iteration progress.
Invoke the procedure that was the third argument to
passing it one argument, the
The result is either the next element in the iteration, or an end
marker as implemented by the
By convention the end marker is the result of
Return the Scheme object that denotes end of iteration.
#t if object is the end of iteration marker.
These functions are provided by the
(gdb iterator) module to
assist in using iterators.
<gdb:iterator> object that will iterate over list.
Return the elements pointed to by iterator as a list.
Return the list of objects obtained by applying proc to the object pointed to by iterator and to each subsequent object.
Apply proc to each element pointed to by iterator. The result is unspecified.
Return the list of elements pointed to by iterator that satisfy pred.
Run iterator until the result of
(pred element) is true
and return that as the result. Otherwise return