hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2021 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." -->
<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Debugging with GDB: Iterators In Guile</title>
 
<meta name="description" content="Debugging with GDB: Iterators In Guile">
<meta name="keywords" content="Debugging with GDB: Iterators In Guile">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Guile-API.html#Guile-API" rel="up" title="Guile API">
<link href="Guile-Auto_002dloading.html#Guile-Auto_002dloading" rel="next" title="Guile Auto-loading">
<link href="Memory-Ports-in-Guile.html#Memory-Ports-in-Guile" rel="previous" title="Memory Ports in Guile">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
 
 
</head>
 
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Iterators-In-Guile"></a>
<div class="header">
<p>
Previous: <a href="Memory-Ports-in-Guile.html#Memory-Ports-in-Guile" accesskey="p" rel="previous">Memory Ports in Guile</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile API</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Iterators-In-Guile-1"></a>
<h4 class="subsubsection">23.3.3.25 Iterators In Guile</h4>
 
<a name="index-guile-iterators"></a>
<a name="index-_003cgdb_003aiterator_003e"></a>
 
<p>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.
</p>
<dl>
<dt><a name="index-make_002diterator"></a>Scheme Procedure: <strong>make-iterator</strong> <em>object progress next!</em></dt>
<dd><p>A <code>&lt;gdb:iterator&gt;</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>
<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>&lt;gdb:iterator&gt;</code> in your own code it is your responsibility to
maintain this invariant.
</p>
<p>A trivial example for illustration&rsquo;s sake:
</p>
<div class="smallexample">
<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></div>
 
<p>Here is a slightly more realistic example, which computes a list of all the
functions in <code>my-global-block</code>.
</p>
<div class="smallexample">
<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></div>
</dd></dl>
 
<dl>
<dt><a name="index-iterator_003f"></a>Scheme Procedure: <strong>iterator?</strong> <em>object</em></dt>
<dd><p>Return <code>#t</code> if <var>object</var> is a <code>&lt;gdb:iterator&gt;</code> object.
Otherwise return <code>#f</code>.
</p></dd></dl>
 
<dl>
<dt><a name="index-iterator_002dobject"></a>Scheme Procedure: <strong>iterator-object</strong> <em>iterator</em></dt>
<dd><p>Return the first argument that was passed to <code>make-iterator</code>.
This is the object being iterated over.
</p></dd></dl>
 
<dl>
<dt><a name="index-iterator_002dprogress"></a>Scheme Procedure: <strong>iterator-progress</strong> <em>iterator</em></dt>
<dd><p>Return the object tracking iteration progress.
</p></dd></dl>
 
<dl>
<dt><a name="index-set_002diterator_002dprogress_0021"></a>Scheme Procedure: <strong>set-iterator-progress!</strong> <em>iterator new-value</em></dt>
<dd><p>Set the object tracking iteration progress.
</p></dd></dl>
 
<dl>
<dt><a name="index-iterator_002dnext_0021"></a>Scheme Procedure: <strong>iterator-next!</strong> <em>iterator</em></dt>
<dd><p>Invoke the procedure that was the third argument to <code>make-iterator</code>,
passing it one argument, the <code>&lt;gdb:iterator&gt;</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></dd></dl>
 
<dl>
<dt><a name="index-end_002dof_002diteration"></a>Scheme Procedure: <strong>end-of-iteration</strong></dt>
<dd><p>Return the Scheme object that denotes end of iteration.
</p></dd></dl>
 
<dl>
<dt><a name="index-end_002dof_002diteration_003f"></a>Scheme Procedure: <strong>end-of-iteration?</strong> <em>object</em></dt>
<dd><p>Return <code>#t</code> if <var>object</var> is the end of iteration marker.
Otherwise return <code>#f</code>.
</p></dd></dl>
 
<p>These functions are provided by the <code>(gdb iterator)</code> module to
assist in using iterators.
</p>
<dl>
<dt><a name="index-make_002dlist_002diterator"></a>Scheme Procedure: <strong>make-list-iterator</strong> <em>list</em></dt>
<dd><p>Return a <code>&lt;gdb:iterator&gt;</code> object that will iterate over <var>list</var>.
</p></dd></dl>
 
<dl>
<dt><a name="index-iterator_002d_003elist"></a>Scheme Procedure: <strong>iterator-&gt;list</strong> <em>iterator</em></dt>
<dd><p>Return the elements pointed to by <var>iterator</var> as a list.
</p></dd></dl>
 
<dl>
<dt><a name="index-iterator_002dmap"></a>Scheme Procedure: <strong>iterator-map</strong> <em>proc iterator</em></dt>
<dd><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></dd></dl>
 
<dl>
<dt><a name="index-iterator_002dfor_002deach"></a>Scheme Procedure: <strong>iterator-for-each</strong> <em>proc iterator</em></dt>
<dd><p>Apply <var>proc</var> to each element pointed to by <var>iterator</var>.
The result is unspecified.
</p></dd></dl>
 
<dl>
<dt><a name="index-iterator_002dfilter"></a>Scheme Procedure: <strong>iterator-filter</strong> <em>pred iterator</em></dt>
<dd><p>Return the list of elements pointed to by <var>iterator</var> that satisfy
<var>pred</var>.
</p></dd></dl>
 
<dl>
<dt><a name="index-iterator_002duntil"></a>Scheme Procedure: <strong>iterator-until</strong> <em>pred iterator</em></dt>
<dd><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></dd></dl>
 
<hr>
<div class="header">
<p>
Previous: <a href="Memory-Ports-in-Guile.html#Memory-Ports-in-Guile" accesskey="p" rel="previous">Memory Ports in Guile</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile API</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
 
 
 
</body>
</html>