Debugging with GDB: Iterators In Guile |
---|
Previous: Memory Ports in Guile, Up: Guile API [Contents][Index]
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.
A <gdb:iterator>
object is constructed with the make-iterator
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 (end-of-iteration)
,
and may be tested with the end-of-iteration?
predicate.
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
functions in my-global-block
.
(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))
Return #t
if object is a <gdb:iterator>
object.
Otherwise return #f
.
Return the first argument that was passed to make-iterator
.
This is the object being iterated over.
Set the object tracking iteration progress.
Invoke the procedure that was the third argument to make-iterator
,
passing it one argument, the <gdb:iterator>
object.
The result is either the next element in the iteration, or an end
marker as implemented by the next!
procedure.
By convention the end marker is the result of (end-of-iteration)
.
Return #t
if object is the end of iteration marker.
Otherwise return #f
.
These functions are provided by the (gdb iterator)
module to
assist in using iterators.
Return a <gdb:iterator>
object that will iterate over 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 #f
.
Previous: Memory Ports in Guile, Up: Guile API [Contents][Index]