Generic-procedures.xhtml 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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>Generic (dynamically overloaded) procedures</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="Overall-Index.xhtml" title="Index"/>
  10. <link rel="next" href="Extended-formals.xhtml" title="Extended Formal Arguments List"/>
  11. </head>
  12. <body>
  13. <header/>
  14. <section class="sect1" title="Generic (dynamically overloaded) procedures" epub:type="subchapter" id="Generic-procedures">
  15. <div class="titlepage">
  16. <div>
  17. <div>
  18. <h2 class="title" style="clear: both">Generic (dynamically overloaded) procedures</h2>
  19. </div>
  20. </div>
  21. </div>
  22. <p>A <em class="firstterm">generic procedure</em> is a collection of <em class="firstterm">method procedures</em>.
  23. (A "method procedure" is not the same as a Java method, but
  24. the terms are related.)
  25. You can call a generic procedure, which selects the "closest
  26. match" among the component method procedures: I.e. the most specific
  27. method procedure that is applicable given the actual arguments.
  28. </p>
  29. <div class="blockquote">
  30. <blockquote class="blockquote">
  31. <p><span class="bold"><strong>Warning:</strong></span> The current implementation of selecting the "best" method
  32. is not reliable if there is more than one method.
  33. It can select depending on argument count, and it can select between
  34. primitive Java methods. However, selecting between different Scheme
  35. procedures based on parameter types should be considered experimental.
  36. The main problem is we can’t determine the most specific
  37. method, so Kawa just tries the methods in order.
  38. </p>
  39. </blockquote>
  40. </div>
  41. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667877360096" class="indexterm"/> <code class="function">make-procedure</code> [<em class="replaceable"><code>keyword:</code></em> <em class="replaceable"><code>value</code></em>]<em class="replaceable"><code>...</code></em> <em class="replaceable"><code>method...</code></em></p>
  42. <div class="blockquote">
  43. <blockquote class="blockquote">
  44. <p>Create a generic procedure given the specific methods.
  45. You can also specify property values for the result.
  46. </p>
  47. <p>The <em class="replaceable"><code>keyword</code></em>s specify how the arguments are used.
  48. A <code class="literal">method:</code> keyword is optional and specifies that the following
  49. argument is a method.
  50. A <code class="literal">name:</code> keyword specifies the name of the resulting procedure,
  51. when used for printing.
  52. Unrecognized keywords are used to set the procedure properties of the result.
  53. </p>
  54. <pre class="screen">(define plus10 (make-procedure foo: 33 name: 'Plus10
  55. method: (lambda (x y) (+ x y 10))
  56. method: (lambda () 10)))
  57. </pre>
  58. </blockquote>
  59. </div>
  60. </section>
  61. <footer>
  62. <div class="navfooter">
  63. <p>
  64. Up: <a accesskey="u" href="Procedures.xhtml">Procedures</a></p>
  65. <p>
  66. Previous: <a accesskey="p" href="Procedure-properties.xhtml">Procedure properties</a></p>
  67. <p>
  68. Next: <a accesskey="n" href="Extended-formals.xhtml">Extended Formal Arguments List</a></p>
  69. </div>
  70. </footer>
  71. </body>
  72. </html>