Dynamic-records.xhtml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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>Creating New Record Types On-the-fly</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="Record-types.xhtml" title="Record types"/>
  10. <link rel="next" href="Method-operations.xhtml" title="Calling Java methods from Scheme"/>
  11. </head>
  12. <body>
  13. <header/>
  14. <section class="sect1" title="Creating New Record Types On-the-fly" epub:type="subchapter" id="Dynamic-records">
  15. <div class="titlepage">
  16. <div>
  17. <div>
  18. <h2 class="title" style="clear: both">Creating New Record Types On-the-fly</h2>
  19. </div>
  20. </div>
  21. </div>
  22. <p>Calling the <code class="literal">make-record-type</code> procedure creates a new record data
  23. type at run-time, without any compile-time support.
  24. It is primarily provided for compatibility; in most cases it is better
  25. to use the <code class="literal">define-record-type</code> form (see <a class="link" href="Record-types.xhtml" title="Record types">Record types</a>).
  26. </p>
  27. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871157952" class="indexterm"/> <code class="function">make-record-type</code> <em class="replaceable"><code>type-name</code></em> <em class="replaceable"><code>field-names</code></em></p>
  28. <div class="blockquote">
  29. <blockquote class="blockquote">
  30. <p>Returns a <em class="firstterm">record-type descriptor</em>, a value representing a new data
  31. type disjoint from all others. The <em class="replaceable"><code>type-name</code></em> argument must be a
  32. string, but is only used for debugging purposes (such as the printed
  33. representation of a record of the new type). The <em class="replaceable"><code>field-names</code></em>
  34. argument is a list of symbols naming the <em class="firstterm">fields</em> of a record of the
  35. new type. It is an error if the list contains any duplicates.
  36. </p>
  37. </blockquote>
  38. </div>
  39. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871147648" class="indexterm"/> <code class="function">record-constructor</code> <em class="replaceable"><code>rtd</code></em> [<em class="replaceable"><code>field-names</code></em>]</p>
  40. <div class="blockquote">
  41. <blockquote class="blockquote">
  42. <p>Returns a procedure for constructing new members of the type represented
  43. by <em class="replaceable"><code>rtd</code></em>. The returned procedure accepts exactly as many arguments
  44. as there are symbols in the given list, <em class="replaceable"><code>field-names</code></em>; these are
  45. used, in order, as the initial values of those fields in a new record,
  46. which is returned by the constructor procedure. The values of any
  47. fields not named in that list are unspecified. The <em class="replaceable"><code>field-names</code></em>
  48. argument defaults to the list of field names in the call to
  49. <code class="literal">make-record-type</code> that created the type represented by <em class="replaceable"><code>rtd</code></em>;
  50. if the <em class="replaceable"><code>field-names</code></em> argument is provided, it is an error if it
  51. contains any duplicates or any symbols not in the default list.
  52. </p>
  53. </blockquote>
  54. </div>
  55. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871138992" class="indexterm"/> <code class="function">record-predicate</code> <em class="replaceable"><code>rtd</code></em></p>
  56. <div class="blockquote">
  57. <blockquote class="blockquote">
  58. <p>Returns a procedure for testing membership in the type represented by
  59. <em class="replaceable"><code>rtd</code></em>. The returned procedure accepts exactly one argument and
  60. returns a true value if the argument is a member of the indicated record
  61. type; it returns a false value otherwise.
  62. </p>
  63. </blockquote>
  64. </div>
  65. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871131568" class="indexterm"/> <code class="function">record-accessor</code> <em class="replaceable"><code>rtd</code></em> <em class="replaceable"><code>field-name</code></em></p>
  66. <div class="blockquote">
  67. <blockquote class="blockquote">
  68. <p>Returns a procedure for reading the value of a particular field of a
  69. member of the type represented by <em class="replaceable"><code>rtd</code></em>. The returned procedure
  70. accepts exactly one argument which must be a record of the appropriate
  71. type; it returns the current value of the field named by the symbol
  72. <em class="replaceable"><code>field-name</code></em> in that record. The symbol <em class="replaceable"><code>field-name</code></em> must be a
  73. member of the list of field-names in the call to <code class="literal">make-record-type</code>
  74. that created the type represented by <em class="replaceable"><code>rtd</code></em>.
  75. </p>
  76. </blockquote>
  77. </div>
  78. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871125520" class="indexterm"/> <code class="function">record-modifier</code> <em class="replaceable"><code>rtd</code></em> <em class="replaceable"><code>field-name</code></em></p>
  79. <div class="blockquote">
  80. <blockquote class="blockquote">
  81. <p>Returns a procedure for writing the value of a particular field of a
  82. member of the type represented by <em class="replaceable"><code>rtd</code></em>. The returned procedure
  83. accepts exactly two arguments: first, a record of the appropriate type,
  84. and second, an arbitrary Scheme value; it modifies the field named by
  85. the symbol <em class="replaceable"><code>field-name</code></em> in that record to contain the given value.
  86. The returned value of the modifier procedure is unspecified. The symbol
  87. <em class="replaceable"><code>field-name</code></em> must be a member of the list of field-names in the call
  88. to <code class="literal">make-record-type</code> that created the type represented by <em class="replaceable"><code>rtd</code></em>.
  89. </p>
  90. </blockquote>
  91. </div>
  92. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871119216" class="indexterm"/> <code class="function">record?</code> <em class="replaceable"><code>obj</code></em></p>
  93. <div class="blockquote">
  94. <blockquote class="blockquote">
  95. <p>Returns a true value if <em class="replaceable"><code>obj</code></em> is a record of any type and a false
  96. value otherwise.
  97. </p>
  98. </blockquote>
  99. </div>
  100. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871115408" class="indexterm"/> <code class="function">record-type-descriptor</code> <em class="replaceable"><code>record</code></em></p>
  101. <div class="blockquote">
  102. <blockquote class="blockquote">
  103. <p>Returns a record-type descriptor representing the type of the given
  104. record. That is, for example, if the returned descriptor were passed to
  105. <code class="literal">record-predicate</code>, the resulting predicate would return a true
  106. value when passed the given record.
  107. </p>
  108. </blockquote>
  109. </div>
  110. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871111392" class="indexterm"/> <code class="function">record-type-name</code> <em class="replaceable"><code>rtd</code></em></p>
  111. <div class="blockquote">
  112. <blockquote class="blockquote">
  113. <p>Returns the type-name associated with the type represented by rtd. The
  114. returned value is <code class="literal">eqv?</code> to the <em class="replaceable"><code>type-name</code></em> argument given in
  115. the call to <code class="literal">make-record-type</code> that created the type represented by
  116. <em class="replaceable"><code>rtd</code></em>.
  117. </p>
  118. </blockquote>
  119. </div>
  120. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667871106208" class="indexterm"/> <code class="function">record-type-field-names</code> <em class="replaceable"><code>rtd</code></em></p>
  121. <div class="blockquote">
  122. <blockquote class="blockquote">
  123. <p>Returns a list of the symbols naming the fields in members of the type
  124. represented by <em class="replaceable"><code>rtd</code></em>. The returned value is <code class="literal">equal?</code> to the
  125. field-names argument given in the call to <code class="literal">make-record-type</code> that
  126. created the type represented by <em class="replaceable"><code>rtd</code></em>.
  127. </p>
  128. </blockquote>
  129. </div>
  130. <p>Records are extensions of the class <code class="literal">Record</code>.
  131. These procedures use the Java 1.1 reflection facility.
  132. </p>
  133. </section>
  134. <footer>
  135. <div class="navfooter">
  136. <p>
  137. Up: <a accesskey="u" href="Objects-Classes-and-Modules.xhtml">Object, Classes and Modules</a></p>
  138. <p>
  139. Previous: <a accesskey="p" href="Record-types.xhtml">Record types</a></p>
  140. <p>
  141. Next: <a accesskey="n" href="Method-operations.xhtml">Calling Java methods from Scheme</a></p>
  142. </div>
  143. </footer>
  144. </body>
  145. </html>