List-Transformations.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <html lang="en">
  2. <head>
  3. <title>List Transformations - 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="Lists.html#Lists" title="Lists">
  9. <link rel="prev" href="Recoverable-Operations.html#Recoverable-Operations" title="Recoverable Operations">
  10. <link rel="next" href="Type-Conversions.html#Type-Conversions" title="Type Conversions">
  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="List-Transformations"></a>
  28. <p>
  29. Next:&nbsp;<a rel="next" accesskey="n" href="Type-Conversions.html#Type-Conversions">Type Conversions</a>,
  30. Previous:&nbsp;<a rel="previous" accesskey="p" href="Recoverable-Operations.html#Recoverable-Operations">Recoverable Operations</a>,
  31. Up:&nbsp;<a rel="up" accesskey="u" href="Lists.html#Lists">Lists</a>
  32. <hr>
  33. </div>
  34. <h4 class="subsection">3.1.3 List Transformations</h4>
  35. <p>Some functions declared in <samp><span class="file">listfuns.h</span></samp> are used to implement the
  36. operations described in <a href="List-Functions.html#List-Functions">List Functions</a>. These functions are able
  37. to report error messages in the event of overflow or other exceptional
  38. <a name="index-overflow-423"></a><a name="index-exceptions-424"></a><a name="index-error-messages-425"></a>conditions, as described in <a href="Error-Messages.html#Error-Messages">Error Messages</a>. The error messages are
  39. represented as lists and returned to the caller. The occurrence of an
  40. error can be detected by the <code>*</code><var>fault</var> flag being set to a
  41. non-zero value. None of these functions ever causes a program exit except
  42. in the event of an internal error.
  43. <div class="defun">
  44. &mdash; Function: void <b>avm_initialize_listfuns</b> ()<var><a name="index-avm_005finitialize_005flistfuns-426"></a></var><br>
  45. <blockquote><p>This has to be called before any of the other functions in this section
  46. is called. It initializes the error message lists, among other things.
  47. </p></blockquote></div>
  48. <div class="defun">
  49. &mdash; Function: void <b>avm_count_listfuns</b> ()<var><a name="index-avm_005fcount_005flistfuns-427"></a></var><br>
  50. <blockquote><p>At the end of a run, a call to this function can verify that no
  51. unreclaimed storage attributable to these functions persists. If it
  52. does, a warning is printed to standard error. If <code>avm_count_lists</code>
  53. is also used, it must be called after this function.
  54. </p></blockquote></div>
  55. <div class="defun">
  56. &mdash; Function: list <b>avm_reversal</b> (<var>list operand, int *fault</var>)<var><a name="index-avm_005freversal-428"></a></var><br>
  57. <blockquote><p>The reversal of the list is returned by this function if no overflow
  58. occurs. A non-zero <code>*</code><var>fault</var> and an error message are returned
  59. otherwise. The original <var>operand</var> still exists in its original
  60. order after this function is called. The amount of additional storage
  61. allocated is proportional only to the length of the list, not the size
  62. of its contents.
  63. </p></blockquote></div>
  64. <div class="defun">
  65. &mdash; Function: list <b>avm_distribution</b> (<var>list operand, int *fault</var>)<var><a name="index-avm_005fdistribution-429"></a></var><br>
  66. <blockquote><p>This function performs the operation described in <a href="Distribute.html#Distribute">Distribute</a>. The
  67. invalid distribution message is returned in the event of a <code>NULL</code>
  68. operand. Otherwise, the returned value is the distributed list. In any event,
  69. the <var>operand</var> is unaffected.
  70. </p></blockquote></div>
  71. <div class="defun">
  72. &mdash; Function: list <b>avm_concatenation</b> (<var>list operand, int *fault</var>)<var><a name="index-avm_005fconcatenation-430"></a></var><br>
  73. <blockquote><p><a name="index-concatenation-431"></a>The <var>operand</var> is treated as a pair of lists to be concatenated, with the
  74. left one in the <code>head</code> field and the right one in the <code>tail</code>
  75. field. The invalid concatenation message is returned in the event of a
  76. <code>NULL</code> <var>operand</var>. The result returned otherwise is the concatenation
  77. of the lists, but the given <var>operand</var> still exists unchanged.
  78. </p></blockquote></div>
  79. <div class="defun">
  80. &mdash; Function: list <b>avm_transposition</b> (<var>list operand, int *fault</var>)<var><a name="index-avm_005ftransposition-432"></a></var><br>
  81. <blockquote><p>The operation performed by this function corresponds to that of
  82. <a href="Transpose.html#Transpose">Transpose</a>. Unlike other functions in this section, the operand
  83. passed to this function is deallocated, and must not be referenced
  84. <a name="index-g_t_0040code_007btranspose_007d-433"></a>thereafter. The transposed list is accessible as the returned value of
  85. this function. If the original <var>operand</var> is still needed
  86. after a call to <code>avm_transposition</code>, only a copy of it should be
  87. passed to it, obtained from <code>avm_copied</code>. The invalid transpose
  88. error message is the result if the operand does not represent a list of equal
  89. length lists.
  90. </p></blockquote></div>
  91. <div class="defun">
  92. &mdash; Function: list <b>avm_membership</b> (<var>list operand, int *fault</var>)<var><a name="index-avm_005fmembership-434"></a></var><br>
  93. <blockquote><p>This function computes the membership predicate described in
  94. <a name="index-g_t_0040code_007bmember_007d-435"></a><a href="Member.html#Member">Member</a>. The operand is a list in which the <code>tail</code> field is
  95. a list that will be searched for the item in the <code>head</code>. If the
  96. item is not found, a <code>NULL</code> list is returned, but otherwise a list
  97. with <code>NULL</code> <code>head</code> and <code>tail</code> fields is returned. If the
  98. operand is <code>NULL</code>, an error message of invalid membership is
  99. returned and <code>*</code><var>fault</var> is set to a non-zero value.
  100. <p>The <code>avm_membership</code> function calls <code>avm_binary_comparison</code>
  101. in order to compare lists, so the same efficiency and side-effect
  102. considerations are relevant to both (<a href="Comparison.html#Comparison">Comparison</a>). It is not
  103. necessary to <code>#include</code> the header file <code>compare.h</code> or to
  104. call <code>avm_initialize_compare</code> in order to use
  105. <code>avm_membership</code>, because they will be done automatically.
  106. </p></blockquote></div>
  107. <div class="defun">
  108. &mdash; Function: list <b>avm_binary_membership</b> (<var>list operand, list members, int *fault</var>)<var>;<a name="index-avm_005fbinary_005fmembership-436"></a></var><br>
  109. <blockquote><p>This function is the same as <code>avm_membership</code> except that it
  110. allows the element and the set of members to be passed as separate
  111. lists instead of being the head and the tail of the same list.
  112. </p></blockquote></div>
  113. <div class="defun">
  114. &mdash; Function: list <b>avm_measurement</b> (<var>list operand, int *fault</var>)<var><a name="index-avm_005fmeasurement-437"></a></var><br>
  115. <blockquote><p>This function implements the operation described in <a href="Weight.html#Weight">Weight</a>, which
  116. pertains to the weight of a tree. The returned value of this function is
  117. a list encoding the weight as a binary number, unless a counter overflow
  118. occurs, in which case it's an error message. As noted previously, the
  119. weight of a tree can easily be exponentially larger than the amount of
  120. <a name="index-native-integer-arithmetic-438"></a>memory it occupies, but this function uses native integer arithmetic for
  121. performance reasons. Hence, a counter overflow is a real
  122. possibility.
  123. </p></blockquote></div>
  124. </body></html>