Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

213 lines
9.3KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Free Software" and "Free Software Needs
  8. Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
  9. and with the Back-Cover Texts as in (a) below.
  10. (a) The FSF's Back-Cover Text is: "You are free to copy and modify
  11. this GNU Manual. Buying copies from GNU Press supports the FSF in
  12. developing GNU and promoting software freedom." -->
  13. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>Iterators In Guile (Debugging with GDB)</title>
  17. <meta name="description" content="Iterators In Guile (Debugging with GDB)">
  18. <meta name="keywords" content="Iterators In Guile (Debugging with GDB)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Guile-API.html#Guile-API" rel="up" title="Guile API">
  26. <link href="Guile-Auto_002dloading.html#Guile-Auto_002dloading" rel="next" title="Guile Auto-loading">
  27. <link href="Memory-Ports-in-Guile.html#Memory-Ports-in-Guile" rel="prev" title="Memory Ports in Guile">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style: oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="Iterators-In-Guile"></a>
  58. <div class="header">
  59. <p>
  60. Previous: <a href="Memory-Ports-in-Guile.html#Memory-Ports-in-Guile" accesskey="p" rel="prev">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>
  61. </div>
  62. <hr>
  63. <a name="Iterators-In-Guile-1"></a>
  64. <h4 class="subsubsection">23.3.3.25 Iterators In Guile</h4>
  65. <a name="index-guile-iterators"></a>
  66. <a name="index-_003cgdb_003aiterator_003e"></a>
  67. <p>A simple iterator facility is provided to allow, for example,
  68. iterating over the set of program symbols without having to first
  69. construct a list of all of them. A useful contribution would be
  70. to add support for SRFI 41 and SRFI 45.
  71. </p>
  72. <dl>
  73. <dt><a name="index-make_002diterator"></a>Scheme Procedure: <strong>make-iterator</strong> <em>object progress next!</em></dt>
  74. <dd><p>A <code>&lt;gdb:iterator&gt;</code> object is constructed with the <code>make-iterator</code>
  75. procedure. It takes three arguments: the object to be iterated over,
  76. an object to record the progress of the iteration, and a procedure to
  77. return the next element in the iteration, or an implementation chosen value
  78. to denote the end of iteration.
  79. </p>
  80. <p>By convention, end of iteration is marked with <code>(end-of-iteration)</code>,
  81. and may be tested with the <code>end-of-iteration?</code> predicate.
  82. The result of <code>(end-of-iteration)</code> is chosen so that it is not
  83. otherwise used by the <code>(gdb)</code> module. If you are using
  84. <code>&lt;gdb:iterator&gt;</code> in your own code it is your responsibility to
  85. maintain this invariant.
  86. </p>
  87. <p>A trivial example for illustration&rsquo;s sake:
  88. </p>
  89. <div class="smallexample">
  90. <pre class="smallexample">(use-modules (gdb iterator))
  91. (define my-list (list 1 2 3))
  92. (define iter
  93. (make-iterator my-list my-list
  94. (lambda (iter)
  95. (let ((l (iterator-progress iter)))
  96. (if (eq? l '())
  97. (end-of-iteration)
  98. (begin
  99. (set-iterator-progress! iter (cdr l))
  100. (car l)))))))
  101. </pre></div>
  102. <p>Here is a slightly more realistic example, which computes a list of all the
  103. functions in <code>my-global-block</code>.
  104. </p>
  105. <div class="smallexample">
  106. <pre class="smallexample">(use-modules (gdb iterator))
  107. (define this-sal (find-pc-line (frame-pc (selected-frame))))
  108. (define this-symtab (sal-symtab this-sal))
  109. (define this-global-block (symtab-global-block this-symtab))
  110. (define syms-iter (make-block-symbols-iterator this-global-block))
  111. (define functions (iterator-filter symbol-function? syms-iter))
  112. </pre></div>
  113. </dd></dl>
  114. <dl>
  115. <dt><a name="index-iterator_003f"></a>Scheme Procedure: <strong>iterator?</strong> <em>object</em></dt>
  116. <dd><p>Return <code>#t</code> if <var>object</var> is a <code>&lt;gdb:iterator&gt;</code> object.
  117. Otherwise return <code>#f</code>.
  118. </p></dd></dl>
  119. <dl>
  120. <dt><a name="index-iterator_002dobject"></a>Scheme Procedure: <strong>iterator-object</strong> <em>iterator</em></dt>
  121. <dd><p>Return the first argument that was passed to <code>make-iterator</code>.
  122. This is the object being iterated over.
  123. </p></dd></dl>
  124. <dl>
  125. <dt><a name="index-iterator_002dprogress"></a>Scheme Procedure: <strong>iterator-progress</strong> <em>iterator</em></dt>
  126. <dd><p>Return the object tracking iteration progress.
  127. </p></dd></dl>
  128. <dl>
  129. <dt><a name="index-set_002diterator_002dprogress_0021"></a>Scheme Procedure: <strong>set-iterator-progress!</strong> <em>iterator new-value</em></dt>
  130. <dd><p>Set the object tracking iteration progress.
  131. </p></dd></dl>
  132. <dl>
  133. <dt><a name="index-iterator_002dnext_0021"></a>Scheme Procedure: <strong>iterator-next!</strong> <em>iterator</em></dt>
  134. <dd><p>Invoke the procedure that was the third argument to <code>make-iterator</code>,
  135. passing it one argument, the <code>&lt;gdb:iterator&gt;</code> object.
  136. The result is either the next element in the iteration, or an end
  137. marker as implemented by the <code>next!</code> procedure.
  138. By convention the end marker is the result of <code>(end-of-iteration)</code>.
  139. </p></dd></dl>
  140. <dl>
  141. <dt><a name="index-end_002dof_002diteration"></a>Scheme Procedure: <strong>end-of-iteration</strong></dt>
  142. <dd><p>Return the Scheme object that denotes end of iteration.
  143. </p></dd></dl>
  144. <dl>
  145. <dt><a name="index-end_002dof_002diteration_003f"></a>Scheme Procedure: <strong>end-of-iteration?</strong> <em>object</em></dt>
  146. <dd><p>Return <code>#t</code> if <var>object</var> is the end of iteration marker.
  147. Otherwise return <code>#f</code>.
  148. </p></dd></dl>
  149. <p>These functions are provided by the <code>(gdb iterator)</code> module to
  150. assist in using iterators.
  151. </p>
  152. <dl>
  153. <dt><a name="index-make_002dlist_002diterator"></a>Scheme Procedure: <strong>make-list-iterator</strong> <em>list</em></dt>
  154. <dd><p>Return a <code>&lt;gdb:iterator&gt;</code> object that will iterate over <var>list</var>.
  155. </p></dd></dl>
  156. <dl>
  157. <dt><a name="index-iterator_002d_003elist"></a>Scheme Procedure: <strong>iterator-&gt;list</strong> <em>iterator</em></dt>
  158. <dd><p>Return the elements pointed to by <var>iterator</var> as a list.
  159. </p></dd></dl>
  160. <dl>
  161. <dt><a name="index-iterator_002dmap"></a>Scheme Procedure: <strong>iterator-map</strong> <em>proc iterator</em></dt>
  162. <dd><p>Return the list of objects obtained by applying <var>proc</var> to the object
  163. pointed to by <var>iterator</var> and to each subsequent object.
  164. </p></dd></dl>
  165. <dl>
  166. <dt><a name="index-iterator_002dfor_002deach"></a>Scheme Procedure: <strong>iterator-for-each</strong> <em>proc iterator</em></dt>
  167. <dd><p>Apply <var>proc</var> to each element pointed to by <var>iterator</var>.
  168. The result is unspecified.
  169. </p></dd></dl>
  170. <dl>
  171. <dt><a name="index-iterator_002dfilter"></a>Scheme Procedure: <strong>iterator-filter</strong> <em>pred iterator</em></dt>
  172. <dd><p>Return the list of elements pointed to by <var>iterator</var> that satisfy
  173. <var>pred</var>.
  174. </p></dd></dl>
  175. <dl>
  176. <dt><a name="index-iterator_002duntil"></a>Scheme Procedure: <strong>iterator-until</strong> <em>pred iterator</em></dt>
  177. <dd><p>Run <var>iterator</var> until the result of <code>(pred element)</code> is true
  178. and return that as the result. Otherwise return <code>#f</code>.
  179. </p></dd></dl>
  180. <hr>
  181. <div class="header">
  182. <p>
  183. Previous: <a href="Memory-Ports-in-Guile.html#Memory-Ports-in-Guile" accesskey="p" rel="prev">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>
  184. </div>
  185. </body>
  186. </html>