| <html lang="en"> |
| <head> |
| <title>Iterators In Guile - Debugging with GDB</title> |
| <meta http-equiv="Content-Type" content="text/html"> |
| <meta name="description" content="Debugging with GDB"> |
| <meta name="generator" content="makeinfo 4.13"> |
| <link title="Top" rel="start" href="index.html#Top"> |
| <link rel="up" href="Guile-API.html#Guile-API" title="Guile API"> |
| <link rel="prev" href="Memory-Ports-in-Guile.html#Memory-Ports-in-Guile" title="Memory Ports in Guile"> |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| <!-- |
| Copyright (C) 1988-2019 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 or |
| any later version published by the Free Software Foundation; with the |
| Invariant Sections being ``Free Software'' and ``Free Software Needs |
| Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' |
| and with the Back-Cover Texts as in (a) below. |
| |
| (a) The FSF's Back-Cover Text is: ``You are free to copy and modify |
| this GNU Manual. Buying copies from GNU Press supports the FSF in |
| developing GNU and promoting software freedom.'' |
| --> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <style type="text/css"><!-- |
| pre.display { font-family:inherit } |
| pre.format { font-family:inherit } |
| pre.smalldisplay { font-family:inherit; font-size:smaller } |
| pre.smallformat { font-family:inherit; font-size:smaller } |
| pre.smallexample { font-size:smaller } |
| pre.smalllisp { font-size:smaller } |
| span.sc { font-variant:small-caps } |
| span.roman { font-family:serif; font-weight:normal; } |
| span.sansserif { font-family:sans-serif; font-weight:normal; } |
| --></style> |
| </head> |
| <body> |
| <div class="node"> |
| <a name="Iterators-In-Guile"></a> |
| <p> |
| Previous: <a rel="previous" accesskey="p" href="Memory-Ports-in-Guile.html#Memory-Ports-in-Guile">Memory Ports in Guile</a>, |
| Up: <a rel="up" accesskey="u" href="Guile-API.html#Guile-API">Guile API</a> |
| <hr> |
| </div> |
| |
| <h5 class="subsubsection">23.3.3.25 Iterators In Guile</h5> |
| |
| <p><a name="index-guile-iterators-2855"></a><a name="index-g_t_003cgdb_003aiterator_003e-2856"></a> |
| 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. |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>make-iterator</b><var> object progress next!<a name="index-make_002diterator-2857"></a></var><br> |
| <blockquote><p>A <code><gdb:iterator></code> object is constructed with the <code>make-iterator</code> |
| 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. |
| |
| <p>By convention, end of iteration is marked with <code>(end-of-iteration)</code>, |
| and may be tested with the <code>end-of-iteration?</code> predicate. |
| The result of <code>(end-of-iteration)</code> is chosen so that it is not |
| otherwise used by the <code>(gdb)</code> module. If you are using |
| <code><gdb:iterator></code> in your own code it is your responsibility to |
| maintain this invariant. |
| |
| <p>A trivial example for illustration's sake: |
| |
| <pre class="smallexample"> (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))))))) |
| </pre> |
| <p>Here is a slightly more realistic example, which computes a list of all the |
| functions in <code>my-global-block</code>. |
| |
| <pre class="smallexample"> (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)) |
| </pre> |
| </blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>iterator?</b><var> object<a name="index-iterator_003f-2858"></a></var><br> |
| <blockquote><p>Return <code>#t</code> if <var>object</var> is a <code><gdb:iterator></code> object. |
| Otherwise return <code>#f</code>. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>iterator-object</b><var> iterator<a name="index-iterator_002dobject-2859"></a></var><br> |
| <blockquote><p>Return the first argument that was passed to <code>make-iterator</code>. |
| This is the object being iterated over. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>iterator-progress</b><var> iterator<a name="index-iterator_002dprogress-2860"></a></var><br> |
| <blockquote><p>Return the object tracking iteration progress. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>set-iterator-progress!</b><var> iterator new-value<a name="index-set_002diterator_002dprogress_0021-2861"></a></var><br> |
| <blockquote><p>Set the object tracking iteration progress. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>iterator-next!</b><var> iterator<a name="index-iterator_002dnext_0021-2862"></a></var><br> |
| <blockquote><p>Invoke the procedure that was the third argument to <code>make-iterator</code>, |
| passing it one argument, the <code><gdb:iterator></code> object. |
| The result is either the next element in the iteration, or an end |
| marker as implemented by the <code>next!</code> procedure. |
| By convention the end marker is the result of <code>(end-of-iteration)</code>. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>end-of-iteration</b><var><a name="index-end_002dof_002diteration-2863"></a></var><br> |
| <blockquote><p>Return the Scheme object that denotes end of iteration. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>end-of-iteration?</b><var> object<a name="index-end_002dof_002diteration_003f-2864"></a></var><br> |
| <blockquote><p>Return <code>#t</code> if <var>object</var> is the end of iteration marker. |
| Otherwise return <code>#f</code>. |
| </p></blockquote></div> |
| |
| <p>These functions are provided by the <code>(gdb iterator)</code> module to |
| assist in using iterators. |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>make-list-iterator</b><var> list<a name="index-make_002dlist_002diterator-2865"></a></var><br> |
| <blockquote><p>Return a <code><gdb:iterator></code> object that will iterate over <var>list</var>. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>iterator->list</b><var> iterator<a name="index-iterator_002d_003elist-2866"></a></var><br> |
| <blockquote><p>Return the elements pointed to by <var>iterator</var> as a list. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>iterator-map</b><var> proc iterator<a name="index-iterator_002dmap-2867"></a></var><br> |
| <blockquote><p>Return the list of objects obtained by applying <var>proc</var> to the object |
| pointed to by <var>iterator</var> and to each subsequent object. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>iterator-for-each</b><var> proc iterator<a name="index-iterator_002dfor_002deach-2868"></a></var><br> |
| <blockquote><p>Apply <var>proc</var> to each element pointed to by <var>iterator</var>. |
| The result is unspecified. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>iterator-filter</b><var> pred iterator<a name="index-iterator_002dfilter-2869"></a></var><br> |
| <blockquote><p>Return the list of elements pointed to by <var>iterator</var> that satisfy |
| <var>pred</var>. |
| </p></blockquote></div> |
| |
| <div class="defun"> |
| — Scheme Procedure: <b>iterator-until</b><var> pred iterator<a name="index-iterator_002duntil-2870"></a></var><br> |
| <blockquote><p>Run <var>iterator</var> until the result of <code>(pred element)</code> is true |
| and return that as the result. Otherwise return <code>#f</code>. |
| </p></blockquote></div> |
| |
| </body></html> |
| |