Filter.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <html lang="en">
  2. <head>
  3. <title>Filter - avram - a virtual machine code interpreter</title>
  4. <meta http-equiv="Content-Type" content="text/html">
  5. <meta name="description" content="avram - a virtual machine code interpreter">
  6. <meta name="generator" content="makeinfo 4.13">
  7. <link title="Top" rel="start" href="index.html#Top">
  8. <link rel="up" href="List-Combinators.html#List-Combinators" title="List Combinators">
  9. <link rel="prev" href="Map.html#Map" title="Map">
  10. <link rel="next" href="Reduce.html#Reduce" title="Reduce">
  11. <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
  12. <meta http-equiv="Content-Style-Type" content="text/css">
  13. <style type="text/css"><!--
  14. pre.display { font-family:inherit }
  15. pre.format { font-family:inherit }
  16. pre.smalldisplay { font-family:inherit; font-size:smaller }
  17. pre.smallformat { font-family:inherit; font-size:smaller }
  18. pre.smallexample { font-size:smaller }
  19. pre.smalllisp { font-size:smaller }
  20. span.sc { font-variant:small-caps }
  21. span.roman { font-family:serif; font-weight:normal; }
  22. span.sansserif { font-family:sans-serif; font-weight:normal; }
  23. --></style>
  24. </head>
  25. <body>
  26. <div class="node">
  27. <a name="Filter"></a>
  28. <p>
  29. Next:&nbsp;<a rel="next" accesskey="n" href="Reduce.html#Reduce">Reduce</a>,
  30. Previous:&nbsp;<a rel="previous" accesskey="p" href="Map.html#Map">Map</a>,
  31. Up:&nbsp;<a rel="up" accesskey="u" href="List-Combinators.html#List-Combinators">List Combinators</a>
  32. <hr>
  33. </div>
  34. <h5 class="subsubsection">2.7.13.2 Filter</h5>
  35. <p><a name="index-g_t_0040code_007bfilter_007d-320"></a>Another well known list operation is that which applies a predicate to
  36. every item of a list, and deletes those for which the predicate is
  37. false. For a predicate with virtual code <var>p</var>, such an
  38. application can be coded conveniently in this form,
  39. <dl>
  40. <dt><em>T23</em><dd>[[<code>filter</code>]] <var>p</var> = <code>((nil,nil),(nil,(</code><var>p</var><code>,nil)))</code>
  41. </dl>
  42. <p class="noindent">which is to say that writing <code>((nil,nil),(nil,(</code><var>p</var><code>,nil)))</code> in
  43. <code>silly</code> is the same as writing <code>filter </code><var>p</var>.
  44. <p>The virtual machine detects code of this form provided that
  45. <var>p</var> is other than <code>nil</code>, and evaluates it consistently
  46. with the following properties, causing it to have the meaning that it
  47. does.
  48. <dl>
  49. <dt><em>P26</em><dd>([[<code>filter</code>]] <var>p</var>) <code>nil</code> = <code>nil</code>
  50. <br><dt><em>P27</em><dd>([[<code>filter</code>]] <var>p</var>) <code>(</code><var>x</var><code>,</code><var>y</var><code>)</code> =
  51. ([[<code>filter</code>]] <var>p</var>) <var>y</var> if <var>p</var> <var>x</var> = <code>nil</code>
  52. <br><dt><em>P28</em><dd>([[<code>filter</code>]] <var>p</var>) <code>(</code><var>x</var><code>,</code><var>y</var><code>)</code> =
  53. <code>(</code><var>x</var><code>,</code>([[<code>filter</code>]] <var>p</var>) <var>y</var><code>)</code> if <var>p</var> <var>x</var> is a non-<code>nil</code> tree
  54. </dl>
  55. </body></html>