Low-level-functions.xhtml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">
  3. <head>
  4. <title>Deprecated low-level functions</title>
  5. <link rel="stylesheet" type="text/css" href="docbook-epub.css"/>
  6. <link rel="stylesheet" type="text/css" href="kawa.css"/>
  7. <script src="kawa-ebook.js" type="text/javascript"/>
  8. <meta name="generator" content="DocBook XSL-NS Stylesheets V1.79.1"/>
  9. <link rel="prev" href="Time-related-functions.xhtml" title="Time-related functions"/>
  10. <link rel="next" href="FAQs.xhtml" title="Frequently Asked Questions"/>
  11. </head>
  12. <body>
  13. <header/>
  14. <section class="sect1" title="Deprecated low-level functions" epub:type="subchapter" id="Low-level-functions">
  15. <div class="titlepage">
  16. <div>
  17. <div>
  18. <h2 class="title" style="clear: both">Deprecated low-level functions</h2>
  19. </div>
  20. </div>
  21. </div>
  22. <p>These sections document older and less convenient ways
  23. to call Java methods, access Java fields, and use Java arrays.
  24. </p>
  25. <span id="Low-level-Method-invocation"/>
  26. <section class="sect2" title="Low-level Method invocation" epub:type="division" id="idm139667869304896">
  27. <div class="titlepage">
  28. <div>
  29. <div>
  30. <h3 class="title">Low-level Method invocation</h3>
  31. </div>
  32. </div>
  33. </div>
  34. <p>The following lower-level primitives require you to specify
  35. the parameter and return types explicitly.
  36. You should probably use the functions <code class="literal">invoke</code> and <code class="literal">invoke-static</code>
  37. (see <a class="link" href="Method-operations.xhtml" title="Calling Java methods from Scheme">Method operations</a>) instead.
  38. </p>
  39. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667869301648" class="indexterm"/> <code class="function">primitive-constructor</code> <em class="replaceable"><code>class</code></em> (<em class="replaceable"><code>argtype</code></em> <em class="replaceable"><code>...</code></em>)</p>
  40. <div class="blockquote">
  41. <blockquote class="blockquote">
  42. <p>Returns a new anonymous procedure, which when called will create
  43. a new object of the specified class, and will then call the
  44. constructor matching the specified argument types.
  45. </p>
  46. </blockquote>
  47. </div>
  48. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667869297184" class="indexterm"/> <code class="function">primitive-virtual-method</code> <em class="replaceable"><code>class</code></em> <em class="replaceable"><code>method</code></em> <em class="replaceable"><code>rtype</code></em> (<em class="replaceable"><code>argtype</code></em> <em class="replaceable"><code>...</code></em>)</p>
  49. <div class="blockquote">
  50. <blockquote class="blockquote">
  51. <p>Returns a new anonymous procedure, which when called will
  52. invoke the instance method whose name is the string <em class="replaceable"><code>method</code></em>
  53. in the class whose name is <em class="replaceable"><code>class</code></em>.
  54. </p>
  55. </blockquote>
  56. </div>
  57. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667869291040" class="indexterm"/> <code class="function">primitive-static-method</code> <em class="replaceable"><code>class</code></em> <em class="replaceable"><code>method</code></em> <em class="replaceable"><code>rtype</code></em> (<em class="replaceable"><code>argtype</code></em> <em class="replaceable"><code>...</code></em>)</p>
  58. <div class="blockquote">
  59. <blockquote class="blockquote">
  60. <p>Returns a new anonymous procedure, which when called will
  61. invoke the static method whose name is the string <em class="replaceable"><code>method</code></em>
  62. in the class whose name is <em class="replaceable"><code>class</code></em>.
  63. </p>
  64. </blockquote>
  65. </div>
  66. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667869284928" class="indexterm"/> <code class="function">primitive-interface-method</code> <em class="replaceable"><code>interface</code></em> <em class="replaceable"><code>method</code></em> <em class="replaceable"><code>rtype</code></em> (<em class="replaceable"><code>argtype</code></em> <em class="replaceable"><code>...</code></em>)</p>
  67. <div class="blockquote">
  68. <blockquote class="blockquote">
  69. <p>Returns a new anonymous procedure, which when called will
  70. invoke the matching method from the interface whose name is <em class="replaceable"><code>interface</code></em>.
  71. </p>
  72. </blockquote>
  73. </div>
  74. <p>The macros return procedure values, just like <code class="literal">lambda</code>.
  75. If the macros are used directly as the procedure of a procedure call,
  76. then kawa can inline the correct bytecodes to call the specified methods.
  77. (Note also that neither macro
  78. checks that there really is a method that matches the specification.)
  79. Otherwise, the Java reflection facility is used.
  80. </p>
  81. </section>
  82. <section class="sect2" title="Low-level field operations" epub:type="division" id="idm139667869278080">
  83. <div class="titlepage">
  84. <div>
  85. <div>
  86. <h3 class="title">Low-level field operations</h3>
  87. </div>
  88. </div>
  89. </div>
  90. <p>The following macros evaluate to procedures that can be used to
  91. access or change the fields of objects or static fields.
  92. The compiler can inline each to a single bytecode instruction
  93. (not counting type conversion).
  94. </p>
  95. <p>These macros are deprecated.
  96. The <code class="literal">fields</code> and <code class="literal">static-field</code> functions
  97. (see <a class="link" href="Field-operations.xhtml" title="Accessing object fields">Field operations</a>) are easier to use, more powerful, and
  98. just as efficient. However, the high-level functions currently do
  99. not provide access to non-public fields.
  100. </p>
  101. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667869274208" class="indexterm"/> <code class="function">primitive-get-field</code> <em class="replaceable"><code>class</code></em> <em class="replaceable"><code>fname</code></em> <em class="replaceable"><code>ftype</code></em></p>
  102. <div class="blockquote">
  103. <blockquote class="blockquote">
  104. <p>Use this to access a field named <em class="replaceable"><code>fname</code></em> having type <em class="replaceable"><code>type</code></em> in
  105. class <em class="replaceable"><code>class</code></em>. Evaluates to a new one-argument procedure,
  106. whose argument is a reference to an object of the specified <em class="replaceable"><code>class</code></em>.
  107. Calling that procedure returns the value of the specified field.
  108. </p>
  109. </blockquote>
  110. </div>
  111. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667869268048" class="indexterm"/> <code class="function">primitive-set-field</code> <em class="replaceable"><code>class</code></em> <em class="replaceable"><code>fname</code></em> <em class="replaceable"><code>ftype</code></em></p>
  112. <div class="blockquote">
  113. <blockquote class="blockquote">
  114. <p>Use this to change a field named <em class="replaceable"><code>fname</code></em> having type <em class="replaceable"><code>type</code></em> in
  115. class <em class="replaceable"><code>class</code></em>. Evaluates to a new two-argument procedure,
  116. whose first argument is a reference to an object of the
  117. specified <em class="replaceable"><code>class</code></em>, and the second argument is the new value.
  118. Calling that procedure sets the field to the specified value.
  119. (This macro’s name does not end in a ‘<code class="literal">!</code>’, because it does not actually
  120. set the field. Rather, it returns a function for setting the field.)
  121. </p>
  122. </blockquote>
  123. </div>
  124. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667869261104" class="indexterm"/> <code class="function">primitive-get-static</code> <em class="replaceable"><code>class</code></em> <em class="replaceable"><code>fname</code></em> <em class="replaceable"><code>ftype</code></em></p>
  125. <div class="blockquote">
  126. <blockquote class="blockquote">
  127. <p>Like <code class="literal">primitive-get-field</code>, but used to access static fields.
  128. Returns a zero-argument function, which when called returns
  129. the value of the static field.
  130. </p>
  131. </blockquote>
  132. </div>
  133. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667869256336" class="indexterm"/> <code class="function">primitive-set-static</code> <em class="replaceable"><code>class</code></em> <em class="replaceable"><code>fname</code></em> <em class="replaceable"><code>ftype</code></em></p>
  134. <div class="blockquote">
  135. <blockquote class="blockquote">
  136. <p>Like <code class="literal">primitive-set-field</code>, but used to modify static fields.
  137. Returns a one-argument function, which when called sets the
  138. value of the static field to the argument.
  139. </p>
  140. </blockquote>
  141. </div>
  142. <span id="Low-level-array-macros"/>
  143. </section>
  144. <section class="sect2" title="Old low-level array macros" epub:type="division" id="idm139667869251152">
  145. <div class="titlepage">
  146. <div>
  147. <div>
  148. <h3 class="title">Old low-level array macros</h3>
  149. </div>
  150. </div>
  151. </div>
  152. <p>The following macros evaluate to procedures that can be used to
  153. manipulate primitive Java array objects.
  154. The compiler can inline each to a single bytecode instruction
  155. (not counting type conversion).
  156. </p>
  157. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667869249472" class="indexterm"/> <code class="function">primitive-array-new</code> <em class="replaceable"><code>element-type</code></em></p>
  158. <div class="blockquote">
  159. <blockquote class="blockquote">
  160. <p>Evaluates to a one-argument procedure. Applying the resulting procedure to
  161. an integer count allocates a new Java array of the specified length,
  162. and whose elements have type <em class="replaceable"><code>element-type</code></em>.
  163. </p>
  164. </blockquote>
  165. </div>
  166. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667869245520" class="indexterm"/> <code class="function">primitive-array-set</code> <em class="replaceable"><code>element-type</code></em></p>
  167. <div class="blockquote">
  168. <blockquote class="blockquote">
  169. <p>Evaluates to a three-argument procedure. The first argument of
  170. the resulting procedure must be an array whose elements have type
  171. <em class="replaceable"><code>element-type</code></em>; the second argument is an index; and the third
  172. argument is a value (coercible to <em class="replaceable"><code>element-type</code></em>) which replaces
  173. the value specified by the index in the given array.
  174. </p>
  175. </blockquote>
  176. </div>
  177. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667869241024" class="indexterm"/> <code class="function">primitive-array-get</code> <em class="replaceable"><code>element-type</code></em></p>
  178. <div class="blockquote">
  179. <blockquote class="blockquote">
  180. <p>Evaluates to a two-argument procedure. The first argument of
  181. the resulting procedure must be an array whose elements have type
  182. <em class="replaceable"><code>element-type</code></em>; the second argument is an index.
  183. Applying the procedure returns the element at the specified index.
  184. </p>
  185. </blockquote>
  186. </div>
  187. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667869237008" class="indexterm"/> <code class="function">primitive-array-length</code> <em class="replaceable"><code>element-type</code></em></p>
  188. <div class="blockquote">
  189. <blockquote class="blockquote">
  190. <p>Evaluates to a one-argument procedure. The argument of
  191. the resulting procedure must be an array whose elements have type
  192. <em class="replaceable"><code>element-type</code></em>.
  193. Applying the procedure returns the length of the array.
  194. (Alternatively, you can use <code class="literal">(field <em class="replaceable"><code>array</code></em> 'length)</code>.)
  195. </p>
  196. </blockquote>
  197. </div>
  198. </section>
  199. </section>
  200. <footer>
  201. <div class="navfooter">
  202. <ul>
  203. <li>
  204. <b class="toc">
  205. <a href="Low-level-functions.xhtml#idm139667869304896">Low-level Method invocation</a>
  206. </b>
  207. </li>
  208. <li>
  209. <b class="toc">
  210. <a href="Low-level-functions.xhtml#idm139667869278080">Low-level field operations</a>
  211. </b>
  212. </li>
  213. <li>
  214. <b class="toc">
  215. <a href="Low-level-functions.xhtml#idm139667869251152">Old low-level array macros</a>
  216. </b>
  217. </li>
  218. </ul>
  219. <p>
  220. Up: <a accesskey="u" href="Miscellaneous.xhtml">Miscellaneous topics</a></p>
  221. <p>
  222. Previous: <a accesskey="p" href="Time-related-functions.xhtml">Time-related functions</a></p>
  223. </div>
  224. </footer>
  225. </body>
  226. </html>