mirror of
https://github.com/ganelson/inform.git
synced 2024-07-16 14:04:24 +03:00
499 lines
90 KiB
HTML
499 lines
90 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<title>Utilities Template</title>
|
|
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
|
|
<meta name="viewport" content="width=device-width initial-scale=1">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<meta http-equiv="Content-Language" content="en-gb">
|
|
|
|
<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
|
|
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
|
|
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
|
|
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
|
|
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
|
|
<script>
|
|
MathJax = {
|
|
tex: {
|
|
inlineMath: '$', '$'], ['\\(', '\\)'
|
|
},
|
|
svg: {
|
|
fontCache: 'global'
|
|
}
|
|
};
|
|
</script>
|
|
<script type="text/javascript" id="MathJax-script" async
|
|
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
|
|
</script>
|
|
|
|
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
|
|
|
|
</head>
|
|
<body class="commentary-font">
|
|
<nav role="navigation">
|
|
<h1><a href="../index.html">
|
|
<img src="../docs-assets/Inform.png" height=72">
|
|
</a></h1>
|
|
<ul><li><a href="../index.html">home</a></li>
|
|
</ul><h2>Compiler</h2><ul>
|
|
<li><a href="../structure.html">structure</a></li>
|
|
<li><a href="../inbuildn.html">inbuild</a></li>
|
|
<li><a href="../inform7n.html">inform7</a></li>
|
|
<li><a href="../intern.html">inter</a></li>
|
|
<li><a href="../services.html">services</a></li>
|
|
<li><a href="../secrets.html">secrets</a></li>
|
|
</ul><h2>Other Tools</h2><ul>
|
|
<li><a href="../inblorbn.html">inblorb</a></li>
|
|
<li><a href="../indocn.html">indoc</a></li>
|
|
<li><a href="../inform6.html">inform6</a></li>
|
|
<li><a href="../inpolicyn.html">inpolicy</a></li>
|
|
<li><a href="../inrtpsn.html">inrtps</a></li>
|
|
</ul><h2>Resources</h2><ul>
|
|
<li><a href="../extensions.html">extensions</a></li>
|
|
<li><a href="../kits.html">kits</a></li>
|
|
</ul><h2>Repository</h2><ul>
|
|
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=18> github</a></li>
|
|
</ul><h2>Related Projects</h2><ul>
|
|
<li><a href="../../../inweb/index.html">inweb</a></li>
|
|
<li><a href="../../../intest/index.html">intest</a></li>
|
|
|
|
</ul>
|
|
</nav>
|
|
<main role="main">
|
|
<!--Weave of 'Utilities Template' generated by Inweb-->
|
|
<div class="breadcrumbs">
|
|
<ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../extensions.html">Kits</a></li><li><a href="index.html">BasicInformKit</a></li><li><b>Utilities Template</b></li></ul></div>
|
|
<p class="purpose">Miscellaneous utility routines for some fundamental I6 needs.</p>
|
|
|
|
<ul class="toc"><li><a href="S-utl.html#SP1">§1. Miscellany</a></li><li><a href="S-utl.html#SP2">§2. Final Code Dependencies</a></li><li><a href="S-utl.html#SP3">§3. Firebreak</a></li><li><a href="S-utl.html#SP4">§4. Print Decimal Number</a></li><li><a href="S-utl.html#SP5">§5. Print Text</a></li><li><a href="S-utl.html#SP6">§6. Print Or Run</a></li><li><a href="S-utl.html#SP7">§7. Saying Phrases</a></li><li><a href="S-utl.html#SP8">§8. Kinds</a></li><li><a href="S-utl.html#SP9">§9. Non-standard enumerations</a></li><li><a href="S-utl.html#SP10">§10. GenerateRandomNumber</a></li><li><a href="S-utl.html#SP11">§11. PrintSpaces</a></li><li><a href="S-utl.html#SP12">§12. SwapWorkflags</a></li><li><a href="S-utl.html#SP13">§13. TestUseOption</a></li><li><a href="S-utl.html#SP14">§14. ZRegion</a></li><li><a href="S-utl.html#SP15">§15. Arrcpy</a></li><li><a href="S-utl.html#SP16">§16. Verbs as Values</a></li><li><a href="S-utl.html#SP17">§17. Seed Random Number Generator Rule</a></li><li><a href="S-utl.html#SP18">§18. Regarding</a></li><li><a href="S-utl.html#SP19">§19. Say One Of</a></li><li><a href="S-utl.html#SP20">§20. Rounding</a></li><li><a href="S-utl.html#SP21">§21. Doing nothing</a></li></ul><hr class="tocbar">
|
|
|
|
<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>§1. Miscellany. </b></p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">#</span><span class="identifier-syntax">Iftrue</span><span class="plain-syntax"> </span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax"> == </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
|
|
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">BLOCKV_STACK_SIZE</span><span class="plain-syntax"> = </span><span class="constant-syntax">224</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">#</span><span class="identifier-syntax">ifnot</span><span class="plain-syntax">;</span>
|
|
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">BLOCKV_STACK_SIZE</span><span class="plain-syntax"> = </span><span class="identifier-syntax">BasicInformKit</span><span class="plain-syntax">`</span><span class="identifier-syntax">STACK_FRAME_CAPACITY_CFGV</span><span class="plain-syntax"> / </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">#</span><span class="identifier-syntax">endif</span><span class="plain-syntax">;</span>
|
|
|
|
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">blockv_stack</span><span class="plain-syntax"> --> </span><span class="identifier-syntax">BLOCKV_STACK_SIZE</span><span class="plain-syntax">;</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">I7SFRAME</span><span class="plain-syntax">;</span>
|
|
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">TEXT_TY_RE_Err</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">prior_named_noun</span><span class="plain-syntax">; </span><span class="comment-syntax">for adaptive text generation</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">prior_named_list</span><span class="plain-syntax">; </span><span class="comment-syntax">ditto: length of list of items</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">prior_named_list_gender</span><span class="plain-syntax">; </span><span class="comment-syntax">ditto: common gender of list of items, or -1</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">story_tense</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="comment-syntax">ditto: present tense</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">story_viewpoint</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">; </span><span class="comment-syntax">ditto: second person singular</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">say__p</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">say__pc</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">say__pc_save</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">say__n</span><span class="plain-syntax">; </span><span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">say__comp</span><span class="plain-syntax">;</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">los_rv</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">parameter_object</span><span class="plain-syntax">; </span><span class="comment-syntax">= I7 "parameter-object" = I7 "container in question"</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">parameter_value</span><span class="plain-syntax">; </span><span class="comment-syntax">not typesafe in I7</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">property_to_be_totalled</span><span class="plain-syntax">; </span><span class="comment-syntax">used to implement "total P of..."</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">property_loop_sign</span><span class="plain-syntax">; </span>\(+1\)<span class="comment-syntax"> for increasing order, </span>\(-1\)<span class="comment-syntax"> for decreasing</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">suppress_scope_loops</span><span class="plain-syntax">;</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">temporary_value</span><span class="plain-syntax">; </span><span class="comment-syntax">can be used anywhere side-effects can't occur</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">clr_fg</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="comment-syntax">foreground colour</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">clr_bg</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="comment-syntax">background colour</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">clr_fgstatus</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="comment-syntax">foreground colour of statusline</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">clr_bgstatus</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="comment-syntax">background colour of statusline</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">clr_on</span><span class="plain-syntax">; </span><span class="comment-syntax">has colour been enabled by the player?</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">statuswin_current</span><span class="plain-syntax">; </span><span class="comment-syntax">if writing to top window</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">suppress_text_substitution</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">deadflag</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
|
|
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">statuswin_cursize</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">statuswin_size</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
|
|
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">debug_dialogue</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">debug_rules</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">debug_rule_nesting</span><span class="plain-syntax">;</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">reason_the_action_failed</span><span class="plain-syntax">; </span><span class="comment-syntax">= I7 "reason the action failed"</span>
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">indef_mode</span><span class="plain-syntax">; </span><span class="comment-syntax">"Indefinite" mode - ie, "take a brick"</span>
|
|
<span class="plain-syntax"> </span><span class="comment-syntax">is in this mode</span>
|
|
|
|
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">standard_interpreter</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
|
|
|
|
<span class="identifier-syntax">Default</span><span class="plain-syntax"> </span><span class="identifier-syntax">LanguageCases</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>§2. Final Code Dependencies. </b>This function definition is a little misleading. The idea is that the
|
|
final code-generator can inject code of its own into the body here: for example,
|
|
the final code-generation for Glulx injects code into <span class="extract"><span class="extract-syntax">FINAL_CODE_STARTUP_R</span></span>
|
|
to use accelerated VM support for certain veneer functions.
|
|
</p>
|
|
|
|
<p class="commentary">The other three are also misleading, in that final code-generation can add more
|
|
helpful code here: the fallbacks here are basic.
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">FINAL_CODE_STARTUP_R</span><span class="plain-syntax"> </span><span class="identifier-syntax">addr</span><span class="plain-syntax"> </span><span class="identifier-syntax">res</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">DebugAction</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax"> </span><span class="identifier-syntax">anames</span><span class="plain-syntax"> </span><span class="identifier-syntax">str</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">a</span><span class="plain-syntax"> >= </span><span class="constant-syntax">4096</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"<fake action "</span><span class="plain-syntax">, </span><span class="identifier-syntax">a</span><span class="plain-syntax">-4096, </span><span class="string-syntax">">"</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"<action "</span><span class="plain-syntax">, </span><span class="identifier-syntax">a</span><span class="plain-syntax">, </span><span class="string-syntax">">"</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">DebugAttribute</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax"> </span><span class="identifier-syntax">anames</span><span class="plain-syntax"> </span><span class="identifier-syntax">str</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"<attribute "</span><span class="plain-syntax">, </span><span class="identifier-syntax">a</span><span class="plain-syntax">, </span><span class="string-syntax">">"</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">DebugProperty</span><span class="plain-syntax"> </span><span class="identifier-syntax">p</span><span class="plain-syntax"> </span><span class="identifier-syntax">pnames</span><span class="plain-syntax"> </span><span class="identifier-syntax">str</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"<property "</span><span class="plain-syntax">, </span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="string-syntax">">"</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>§3. Firebreak. </b></p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">Protect_I7_Arrays</span><span class="plain-syntax"> --> </span><span class="constant-syntax">16339</span><span class="plain-syntax"> </span><span class="constant-syntax">12345</span><span class="plain-syntax">;</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>§4. Print Decimal Number. </b><span class="extract"><span class="extract-syntax">DecimalNumber</span></span> is a trivial function which just prints a number, in decimal
|
|
digits. It is left over from the I6 library's support routines for Glulx,
|
|
where it was intended as a stub to pass to the Glulx <span class="extract"><span class="extract-syntax">Glulx_PrintAnything</span></span> routine
|
|
(which I7 does not use). In I7, however, it's also used as the default
|
|
printing routine for new kinds of value.
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">DecimalNumber</span><span class="plain-syntax"> </span><span class="identifier-syntax">num</span><span class="plain-syntax">; </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="identifier-syntax">num</span><span class="plain-syntax">; ];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>§5. Print Text. </b>The routine for printing an I7 "text" value, which might be text with or
|
|
without substitutions.
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">PrintI6Text</span><span class="plain-syntax"> </span><span class="identifier-syntax">x</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">String</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">x</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Routine</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax">)();</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="identifier-syntax">EMPTY_TEXT_PACKED</span><span class="plain-syntax">) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">I7_String</span><span class="plain-syntax"> </span><span class="identifier-syntax">x</span><span class="plain-syntax">; </span><span class="identifier-syntax">TEXT_TY_Say</span><span class="plain-syntax">(</span><span class="identifier-syntax">x</span><span class="plain-syntax">); ]; </span><span class="comment-syntax">An alternative name now used only by extensions</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>§6. Print Or Run. </b>This utility remains from the old I6 library: it essentially treats a
|
|
property as textual and prints it where possible. Where the <span class="extract"><span class="extract-syntax">no_break</span></span>
|
|
flag is set, we expect the text to form only a small part of a paragraph,
|
|
and it's inappropriate to break here: for instance, for printing the
|
|
"printed name" of an object. Where the flag is clear, however, the text
|
|
is expected to form its own paragraph.
|
|
</p>
|
|
|
|
<p class="commentary">Where <span class="extract"><span class="extract-syntax">PrintOrRun</span></span> is used in breaking mode, which is only for a very few
|
|
properties in I7 (indeed at present only <span class="extract"><span class="extract-syntax">initial</span></span> and <span class="extract"><span class="extract-syntax">description</span></span>),
|
|
the routine called is given the chance to decide whether to print or not.
|
|
It should return <span class="extract"><span class="extract-syntax">true</span></span> or <span class="extract"><span class="extract-syntax">false</span></span> according to whether it did so; this
|
|
allows us to divide the paragraph or not accordingly.
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">PrintOrRun</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="identifier-syntax">prop</span><span class="plain-syntax"> </span><span class="identifier-syntax">no_break</span><span class="plain-syntax"> </span><span class="identifier-syntax">pv</span><span class="plain-syntax"> </span><span class="identifier-syntax">st</span><span class="plain-syntax"> </span><span class="identifier-syntax">routine_return_value</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">self</span><span class="plain-syntax">; </span><span class="identifier-syntax">self</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">prop</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="identifier-syntax">name</span><span class="plain-syntax">) </span><span class="identifier-syntax">prop</span><span class="plain-syntax">; </span><span class="identifier-syntax">routine_return_value</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">routine_return_value</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TEXT_TY_Say</span><span class="plain-syntax">(</span><span class="identifier-syntax">obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">prop</span><span class="plain-syntax">);</span>
|
|
<span class="plain-syntax"> }</span>
|
|
<span class="plain-syntax"> @</span><span class="identifier-syntax">pull</span><span class="plain-syntax"> </span><span class="identifier-syntax">self</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">routine_return_value</span><span class="plain-syntax">) {</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">say__p</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">no_break</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) {</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">new_line</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">DivideParagraphPoint</span><span class="plain-syntax">();</span>
|
|
<span class="plain-syntax"> }</span>
|
|
<span class="plain-syntax"> }</span>
|
|
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">routine_return_value</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">DA_Number</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">; </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">; ];</span>
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">DA_TruthState</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">n</span><span class="plain-syntax">==0) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"false"</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"true"</span><span class="plain-syntax">; ];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>§7. Saying Phrases. </b></p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">SayPhraseName</span><span class="plain-syntax"> </span><span class="identifier-syntax">closure</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">closure</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"nothing"</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="reserved-syntax">string</span><span class="plain-syntax">) </span><span class="identifier-syntax">closure</span><span class="plain-syntax">-->2;</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>§8. Kinds. </b></p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">KindAtomic</span><span class="plain-syntax"> </span><span class="identifier-syntax">kind</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">kind</span><span class="plain-syntax"> >= </span><span class="constant-syntax">0</span><span class="plain-syntax">) && (</span><span class="identifier-syntax">kind</span><span class="plain-syntax"> < </span><span class="identifier-syntax">BASE_KIND_HWM</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">kind</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">kind</span><span class="plain-syntax">-->0;</span>
|
|
<span class="plain-syntax">];</span>
|
|
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">KindBaseArity</span><span class="plain-syntax"> </span><span class="identifier-syntax">kind</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">kind</span><span class="plain-syntax"> >= </span><span class="constant-syntax">0</span><span class="plain-syntax">) && (</span><span class="identifier-syntax">kind</span><span class="plain-syntax"> < </span><span class="identifier-syntax">BASE_KIND_HWM</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">kind</span><span class="plain-syntax">-->1;</span>
|
|
<span class="plain-syntax">];</span>
|
|
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">KindBaseTerm</span><span class="plain-syntax"> </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">kind</span><span class="plain-syntax"> >= </span><span class="constant-syntax">0</span><span class="plain-syntax">) && (</span><span class="identifier-syntax">kind</span><span class="plain-syntax"> < </span><span class="identifier-syntax">BASE_KIND_HWM</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">UNKNOWN_TY</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">kind</span><span class="plain-syntax">-->(2+</span><span class="identifier-syntax">n</span><span class="plain-syntax">);</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>§9. Non-standard enumerations. </b>This is for enumerations whose values are scattered: say, for a kind where
|
|
the valid runtime values are 3, 15 and 421. Next after 3 is 15; previous
|
|
is 421, and so on.
|
|
</p>
|
|
|
|
<p class="commentary">The instances array supplied has the extent in word 0, which is in effect
|
|
the number of valid instances. This is guaranteed to be at least 1.
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">NextEnumVal</span><span class="plain-syntax"> </span><span class="identifier-syntax">inst</span><span class="plain-syntax"> </span><span class="identifier-syntax">instances</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> = </span><span class="identifier-syntax">instances</span><span class="plain-syntax">-->0;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">i</span><span class="plain-syntax"><=</span><span class="identifier-syntax">count</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">instances</span><span class="plain-syntax">--></span><span class="identifier-syntax">i</span><span class="plain-syntax"> == </span><span class="identifier-syntax">inst</span><span class="plain-syntax">)</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">instances</span><span class="plain-syntax">-->(</span><span class="identifier-syntax">i</span><span class="plain-syntax">%</span><span class="identifier-syntax">count</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">instances</span><span class="plain-syntax">-->1; </span><span class="comment-syntax">Should not ever happen</span>
|
|
<span class="plain-syntax">];</span>
|
|
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">PrevEnumVal</span><span class="plain-syntax"> </span><span class="identifier-syntax">inst</span><span class="plain-syntax"> </span><span class="identifier-syntax">instances</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> = </span><span class="identifier-syntax">instances</span><span class="plain-syntax">-->0;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">i</span><span class="plain-syntax"><=</span><span class="identifier-syntax">count</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">instances</span><span class="plain-syntax">--></span><span class="identifier-syntax">i</span><span class="plain-syntax"> == </span><span class="identifier-syntax">inst</span><span class="plain-syntax">)</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">instances</span><span class="plain-syntax">-->((</span><span class="identifier-syntax">i</span><span class="plain-syntax">+</span><span class="identifier-syntax">count</span><span class="plain-syntax">-2)%</span><span class="identifier-syntax">count</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">instances</span><span class="plain-syntax">-->1; </span><span class="comment-syntax">Should not ever happen</span>
|
|
<span class="plain-syntax">];</span>
|
|
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">RandomEnumVal</span><span class="plain-syntax"> </span><span class="identifier-syntax">instances</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax"> </span><span class="identifier-syntax">b</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> </span><span class="identifier-syntax">a_index</span><span class="plain-syntax"> </span><span class="identifier-syntax">b_index</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> = </span><span class="identifier-syntax">instances</span><span class="plain-syntax">-->0;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">a</span><span class="plain-syntax"> == </span><span class="identifier-syntax">b</span><span class="plain-syntax">) {</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">a</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">instances</span><span class="plain-syntax">-->(</span><span class="reserved-syntax">random</span><span class="plain-syntax">(</span><span class="identifier-syntax">count</span><span class="plain-syntax">));</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> }</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">c</span><span class="plain-syntax"> <= </span><span class="identifier-syntax">count</span><span class="plain-syntax">: </span><span class="identifier-syntax">c</span><span class="plain-syntax">++) {</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">instances</span><span class="plain-syntax">--></span><span class="identifier-syntax">c</span><span class="plain-syntax"> == </span><span class="identifier-syntax">a</span><span class="plain-syntax">)</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">a_index</span><span class="plain-syntax"> = </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">instances</span><span class="plain-syntax">--></span><span class="identifier-syntax">c</span><span class="plain-syntax"> == </span><span class="identifier-syntax">b</span><span class="plain-syntax">)</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">b_index</span><span class="plain-syntax"> = </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> }</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">a_index</span><span class="plain-syntax"> > </span><span class="identifier-syntax">b_index</span><span class="plain-syntax">) { </span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="identifier-syntax">a_index</span><span class="plain-syntax">; </span><span class="identifier-syntax">a_index</span><span class="plain-syntax"> = </span><span class="identifier-syntax">b_index</span><span class="plain-syntax">; </span><span class="identifier-syntax">b_index</span><span class="plain-syntax"> = </span><span class="identifier-syntax">c</span><span class="plain-syntax">; }</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">instances</span><span class="plain-syntax">-->(</span><span class="identifier-syntax">a_index</span><span class="plain-syntax"> + </span><span class="reserved-syntax">random</span><span class="plain-syntax">(</span><span class="identifier-syntax">b_index</span><span class="plain-syntax"> - </span><span class="identifier-syntax">a_index</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">) - </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
|
|
<span class="plain-syntax">];</span>
|
|
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">IndexOfEnumVal</span><span class="plain-syntax"> </span><span class="identifier-syntax">instances</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> = </span><span class="identifier-syntax">instances</span><span class="plain-syntax">-->0;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">c</span><span class="plain-syntax"> <= </span><span class="identifier-syntax">count</span><span class="plain-syntax">: </span><span class="identifier-syntax">c</span><span class="plain-syntax">++)</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">instances</span><span class="plain-syntax">--></span><span class="identifier-syntax">c</span><span class="plain-syntax"> == </span><span class="identifier-syntax">a</span><span class="plain-syntax">)</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>§10. GenerateRandomNumber. </b>The following uses the virtual machine's RNG (via the I6 built-in function
|
|
<span class="extract"><span class="extract-syntax">random</span></span>) to produce a uniformly random integer in the range \(n\) to \(m\)
|
|
inclusive, where \(n\) and \(m\) are allowed to be either way around; so that
|
|
a random number between 17 and 4 is the same thing as a random number
|
|
between 4 and 17, and there is therefore no pair of \(n\) and \(m\) corresponding
|
|
to an empty range of values.
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">GenerateRandomNumber</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> </span><span class="identifier-syntax">m</span><span class="plain-syntax"> </span><span class="identifier-syntax">s</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">n</span><span class="plain-syntax">==</span><span class="identifier-syntax">m</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">n</span><span class="plain-syntax">></span><span class="identifier-syntax">m</span><span class="plain-syntax">) { </span><span class="identifier-syntax">s</span><span class="plain-syntax"> = </span><span class="identifier-syntax">n</span><span class="plain-syntax">; </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><span class="identifier-syntax">m</span><span class="plain-syntax">; </span><span class="identifier-syntax">m</span><span class="plain-syntax"> = </span><span class="identifier-syntax">s</span><span class="plain-syntax">; }</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">--;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">random</span><span class="plain-syntax">(</span><span class="identifier-syntax">m</span><span class="plain-syntax">-</span><span class="identifier-syntax">n</span><span class="plain-syntax">) + </span><span class="identifier-syntax">n</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">R_DecimalNumber</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GenerateRandomNumber</span><span class="plain-syntax">;</span>
|
|
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">R_PrintTimeOfDay</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GenerateRandomNumber</span><span class="plain-syntax">;</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>§11. PrintSpaces. </b>Which prints a row of \(n\) spaces, for \(n\geq 0\).
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">PrintSpaces</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">n</span><span class="plain-syntax"> > </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">" "</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><span class="identifier-syntax">n</span><span class="plain-syntax"> - </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> }</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>§12. SwapWorkflags. </b>Recall that we have two general-purpose temporary attributes for each object:
|
|
<span class="extract"><span class="extract-syntax">workflag</span></span> and <span class="extract"><span class="extract-syntax">workflag2</span></span>. The following swaps their values over for every
|
|
object at once.
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">SwapWorkflags</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="identifier-syntax">lst</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax">) {</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">lst</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="reserved-syntax">has</span><span class="plain-syntax"> </span><span class="identifier-syntax">workflag2</span><span class="plain-syntax">) </span><span class="identifier-syntax">lst</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">give</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> ~</span><span class="identifier-syntax">workflag2</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="reserved-syntax">has</span><span class="plain-syntax"> </span><span class="identifier-syntax">workflag</span><span class="plain-syntax">) </span><span class="reserved-syntax">give</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="identifier-syntax">workflag2</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">give</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> ~</span><span class="identifier-syntax">workflag</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">lst</span><span class="plain-syntax">) </span><span class="reserved-syntax">give</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj</span><span class="plain-syntax"> </span><span class="identifier-syntax">workflag</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> }</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>§13. TestUseOption. </b>This routine, compiled by Inform, returns <span class="extract"><span class="extract-syntax">true</span></span> if the supplied argument is the
|
|
number of a use option in force for the current run of Inform, and <span class="extract"><span class="extract-syntax">false</span></span>
|
|
otherwise.
|
|
</p>
|
|
|
|
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>§14. ZRegion. </b>I7 contains many relics from I6, but here's a relic from I5: a routine which
|
|
used to determine the metaclass of a value, before that concept was given a
|
|
name. In I6 code, it can be implemented simply using <span class="extract"><span class="extract-syntax">metaclass</span></span>, as the
|
|
following shows. (The name is from "region of the Z-machine".)
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">ZRegion</span><span class="plain-syntax"> </span><span class="identifier-syntax">addr</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="reserved-syntax">metaclass</span><span class="plain-syntax">(</span><span class="identifier-syntax">addr</span><span class="plain-syntax">)) {</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">: </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">Object</span><span class="plain-syntax">, </span><span class="identifier-syntax">Class</span><span class="plain-syntax">: </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">Routine</span><span class="plain-syntax">: </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">String</span><span class="plain-syntax">: </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">3</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> }</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>§15. Arrcpy. </b>This is not quite so efficient as Memcpy, but not terrible.
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">Arrcpy</span><span class="plain-syntax"> </span><span class="identifier-syntax">to_array</span><span class="plain-syntax"> </span><span class="identifier-syntax">to_entry_size</span><span class="plain-syntax"> </span><span class="identifier-syntax">from_array</span><span class="plain-syntax"> </span><span class="identifier-syntax">from_entry_size</span><span class="plain-syntax"> </span><span class="identifier-syntax">no_entries</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">to_entry_size</span><span class="plain-syntax"> == </span><span class="identifier-syntax">from_entry_size</span><span class="plain-syntax">)</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">Memcpy</span><span class="plain-syntax">(</span><span class="identifier-syntax">to_array</span><span class="plain-syntax">, </span><span class="identifier-syntax">from_array</span><span class="plain-syntax">, </span><span class="identifier-syntax">to_entry_size</span><span class="plain-syntax">*</span><span class="identifier-syntax">no_entries</span><span class="plain-syntax">);</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">to_entry_size</span><span class="plain-syntax"> == </span><span class="constant-syntax">2</span><span class="plain-syntax">) && (</span><span class="identifier-syntax">from_entry_size</span><span class="plain-syntax"> == </span><span class="constant-syntax">4</span><span class="plain-syntax">)) {</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">: </span><span class="identifier-syntax">n</span><span class="plain-syntax"><</span><span class="identifier-syntax">no_entries</span><span class="plain-syntax">: </span><span class="identifier-syntax">n</span><span class="plain-syntax">++) {</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="identifier-syntax">from_array</span><span class="plain-syntax">--></span><span class="identifier-syntax">n</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">to_array</span><span class="plain-syntax">->0 = (</span><span class="identifier-syntax">val</span><span class="plain-syntax">/256)%256; </span><span class="identifier-syntax">to_array</span><span class="plain-syntax">->1 = </span><span class="identifier-syntax">val</span><span class="plain-syntax">%256;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">to_array</span><span class="plain-syntax"> = </span><span class="identifier-syntax">to_array</span><span class="plain-syntax"> + </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> }</span>
|
|
<span class="plain-syntax"> } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="string-syntax">"*** Arrcpy doesn't support this ***"</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>§16. Verbs as Values. </b></p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">PrintVerbAsValue</span><span class="plain-syntax"> </span><span class="identifier-syntax">vb</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">vb</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"(no verb)"</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">else</span><span class="plain-syntax"> { </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"verb "</span><span class="plain-syntax">; </span><span class="identifier-syntax">vb</span><span class="plain-syntax">(1); }</span>
|
|
<span class="plain-syntax">];</span>
|
|
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">VerbIsMeaningful</span><span class="plain-syntax"> </span><span class="identifier-syntax">vb</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">vb</span><span class="plain-syntax">) && (</span><span class="identifier-syntax">BlkValueCompare</span><span class="plain-syntax">(</span><span class="identifier-syntax">vb</span><span class="plain-syntax">(</span><span class="identifier-syntax">CV_MEANING</span><span class="plain-syntax">), </span><span class="identifier-syntax">MEANINGLESS_RR</span><span class="plain-syntax">) ~= </span><span class="constant-syntax">0</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">VerbIsModal</span><span class="plain-syntax"> </span><span class="identifier-syntax">vb</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">vb</span><span class="plain-syntax">) && (</span><span class="identifier-syntax">vb</span><span class="plain-syntax">(</span><span class="identifier-syntax">CV_MODAL</span><span class="plain-syntax">))) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP17" class="paragraph-anchor"></a><b>§17. Seed Random Number Generator Rule. </b>Unless a seed is provided by Inform, and it won't be for released story files,
|
|
the VM's interpreter is supposed to start up with a good seed in its random
|
|
number generator: something usually derived from, say, the milliseconds part
|
|
of the current time of day, which is unlikely to repeat or show any pattern
|
|
in real-world use. However, early Z-machine interpreters often did this quite
|
|
badly, starting with poor seed values which meant that the first few random
|
|
numbers always had something in common (being fairly small in their range,
|
|
for instance). To obviate this we extract and throw away 100 random numbers
|
|
to get the generator going, shaking out more obvious early patterns, but
|
|
that cannot really help much if the VM interpreter's RNG is badly written.
|
|
"Anyone who considers arithmetical methods of producing random digits is,
|
|
of course, in a state of sin" (von Neumann).
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">SEED_RANDOM_NUMBER_GENERATOR_R</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">RNG_SEED_AT_START_OF_PLAY</span><span class="plain-syntax">) </span><span class="identifier-syntax">VM_Seed_RNG</span><span class="plain-syntax">(</span><span class="identifier-syntax">RNG_SEED_AT_START_OF_PLAY</span><span class="plain-syntax">);</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">i</span><span class="plain-syntax"><=100: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="reserved-syntax">random</span><span class="plain-syntax">(</span><span class="identifier-syntax">i</span><span class="plain-syntax">);</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP18" class="paragraph-anchor"></a><b>§18. Regarding. </b>These are used with adaptive text.
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">RegardingSingleObject</span><span class="plain-syntax"> </span><span class="identifier-syntax">obj</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">prior_named_list</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">prior_named_list_gender</span><span class="plain-syntax"> = -1;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">prior_named_noun</span><span class="plain-syntax"> = </span><span class="identifier-syntax">obj</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">RegardingNumber</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">prior_named_list</span><span class="plain-syntax"> = </span><span class="identifier-syntax">n</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">prior_named_list_gender</span><span class="plain-syntax"> = -1;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">prior_named_noun</span><span class="plain-syntax"> = </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP19" class="paragraph-anchor"></a><b>§19. Say One Of. </b>These routines are described in the Extensions chapter of the Inform
|
|
documentation.
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">I7_SOO_PAR</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax">; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax"> <= </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax">; </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">random</span><span class="plain-syntax">(</span><span class="identifier-syntax">count</span><span class="plain-syntax">); ];</span>
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">I7_SOO_RAN</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax">; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax"> <= </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="identifier-syntax">oldval</span><span class="plain-syntax">; </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">oldval</span><span class="plain-syntax">) </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="reserved-syntax">random</span><span class="plain-syntax">(</span><span class="identifier-syntax">count</span><span class="plain-syntax">); </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax">; ];</span>
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">I7_SOO_STI</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax">; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">oldval</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax">; </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">I7_SOO_PAR</span><span class="plain-syntax">(</span><span class="identifier-syntax">oldval</span><span class="plain-syntax">, </span><span class="identifier-syntax">count</span><span class="plain-syntax">); ];</span>
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">I7_SOO_CYC</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax">; </span><span class="identifier-syntax">oldval</span><span class="plain-syntax">++; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> > </span><span class="identifier-syntax">count</span><span class="plain-syntax">) </span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax">; ];</span>
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">I7_SOO_STOP</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax">; </span><span class="identifier-syntax">oldval</span><span class="plain-syntax">++; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> > </span><span class="identifier-syntax">count</span><span class="plain-syntax">) </span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> = </span><span class="identifier-syntax">count</span><span class="plain-syntax">; </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax">; ];</span>
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">I7_SOO_TAP</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> </span><span class="identifier-syntax">tn</span><span class="plain-syntax"> </span><span class="identifier-syntax">rn</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax"> <= </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax">; </span><span class="identifier-syntax">tn</span><span class="plain-syntax"> = </span><span class="identifier-syntax">count</span><span class="plain-syntax">*(</span><span class="identifier-syntax">count</span><span class="plain-syntax">+1)/2;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">rn</span><span class="plain-syntax"> = </span><span class="reserved-syntax">random</span><span class="plain-syntax">(</span><span class="identifier-syntax">tn</span><span class="plain-syntax">); </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">c</span><span class="plain-syntax"><=</span><span class="identifier-syntax">count</span><span class="plain-syntax">:</span><span class="identifier-syntax">c</span><span class="plain-syntax">++) { </span><span class="identifier-syntax">rn</span><span class="plain-syntax"> = </span><span class="identifier-syntax">rn</span><span class="plain-syntax"> - </span><span class="identifier-syntax">c</span><span class="plain-syntax">; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rn</span><span class="plain-syntax"><=0) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax">-</span><span class="identifier-syntax">c</span><span class="plain-syntax">+1); } ];</span>
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">I7_SOO_TRAN</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax">; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">oldval</span><span class="plain-syntax"><</span><span class="identifier-syntax">count</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax">+1;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax"> + </span><span class="identifier-syntax">I7_SOO_RAN</span><span class="plain-syntax">(</span><span class="identifier-syntax">oldval</span><span class="plain-syntax">%(</span><span class="identifier-syntax">count</span><span class="plain-syntax">+1), </span><span class="identifier-syntax">count</span><span class="plain-syntax">); ];</span>
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">I7_SOO_TPAR</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax">; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">oldval</span><span class="plain-syntax"><</span><span class="identifier-syntax">count</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax">+1;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax"> + </span><span class="identifier-syntax">I7_SOO_PAR</span><span class="plain-syntax">(</span><span class="identifier-syntax">oldval</span><span class="plain-syntax">%(</span><span class="identifier-syntax">count</span><span class="plain-syntax">+1), </span><span class="identifier-syntax">count</span><span class="plain-syntax">); ];</span>
|
|
|
|
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">I7_SOO_SHUF</span><span class="plain-syntax">->32;</span>
|
|
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">I7_SOO_SHU</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> </span><span class="identifier-syntax">sd</span><span class="plain-syntax"> </span><span class="identifier-syntax">ct</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax"> </span><span class="identifier-syntax">s</span><span class="plain-syntax"> </span><span class="identifier-syntax">ssd</span><span class="plain-syntax"> </span><span class="identifier-syntax">scope</span><span class="plain-syntax"> </span><span class="identifier-syntax">cc</span><span class="plain-syntax"> </span><span class="identifier-syntax">base</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">base</span><span class="plain-syntax"> = </span><span class="identifier-syntax">count</span><span class="plain-syntax">+1;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="identifier-syntax">oldval</span><span class="plain-syntax">%</span><span class="identifier-syntax">base</span><span class="plain-syntax">; </span><span class="identifier-syntax">oldval</span><span class="plain-syntax"> = </span><span class="identifier-syntax">oldval</span><span class="plain-syntax">/</span><span class="identifier-syntax">base</span><span class="plain-syntax">; </span><span class="identifier-syntax">ct</span><span class="plain-syntax"> = </span><span class="identifier-syntax">oldval</span><span class="plain-syntax">%</span><span class="identifier-syntax">base</span><span class="plain-syntax">; </span><span class="identifier-syntax">sd</span><span class="plain-syntax"> = </span><span class="identifier-syntax">oldval</span><span class="plain-syntax">/</span><span class="identifier-syntax">base</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax"> > </span><span class="constant-syntax">32</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">I7_SOO_PAR</span><span class="plain-syntax">(</span><span class="identifier-syntax">oldval</span><span class="plain-syntax">, </span><span class="identifier-syntax">count</span><span class="plain-syntax">);</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">count</span><span class="plain-syntax"> <= </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="identifier-syntax">count</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
|
|
<span class="plain-syntax"> </span><span class="comment-syntax">rint "^In v=", v, " ct=", ct, " sd=", sd, "^";</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">cc</span><span class="plain-syntax"> = </span><span class="identifier-syntax">base</span><span class="plain-syntax">*</span><span class="identifier-syntax">base</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">scope</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">MAX_POSITIVE_NUMBER</span><span class="plain-syntax">-1)/</span><span class="identifier-syntax">cc</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="comment-syntax">rint "Scope = ", scope, "^";</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sd</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="identifier-syntax">sd</span><span class="plain-syntax"> = </span><span class="reserved-syntax">random</span><span class="plain-syntax">(</span><span class="identifier-syntax">scope</span><span class="plain-syntax">); </span><span class="identifier-syntax">ct</span><span class="plain-syntax">=0; }</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0:</span><span class="identifier-syntax">i</span><span class="plain-syntax"><</span><span class="identifier-syntax">count</span><span class="plain-syntax">:</span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">I7_SOO_SHUF</span><span class="plain-syntax">-></span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">ssd</span><span class="plain-syntax"> = </span><span class="identifier-syntax">sd</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=0:</span><span class="identifier-syntax">i</span><span class="plain-syntax"><</span><span class="identifier-syntax">count</span><span class="plain-syntax">-1:</span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">sd</span><span class="plain-syntax">)%(</span><span class="identifier-syntax">count</span><span class="plain-syntax">-</span><span class="identifier-syntax">i</span><span class="plain-syntax">)+</span><span class="identifier-syntax">i</span><span class="plain-syntax">; </span><span class="identifier-syntax">sd</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">sd</span><span class="plain-syntax">*31973)+17; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sd</span><span class="plain-syntax"><0) </span><span class="identifier-syntax">sd</span><span class="plain-syntax">=-</span><span class="identifier-syntax">sd</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">s</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I7_SOO_SHUF</span><span class="plain-syntax">-></span><span class="identifier-syntax">j</span><span class="plain-syntax">; </span><span class="identifier-syntax">I7_SOO_SHUF</span><span class="plain-syntax">-></span><span class="identifier-syntax">j</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I7_SOO_SHUF</span><span class="plain-syntax">-></span><span class="identifier-syntax">i</span><span class="plain-syntax">; </span><span class="identifier-syntax">I7_SOO_SHUF</span><span class="plain-syntax">-></span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">s</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> }</span>
|
|
<span class="plain-syntax"> </span><span class="comment-syntax">or (i=0:i<count:i++) print I7_SOO_SHUF->i, " "; print "^";</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">I7_SOO_SHUF</span><span class="plain-syntax">-></span><span class="identifier-syntax">ct</span><span class="plain-syntax">)+1;</span>
|
|
<span class="plain-syntax"> </span><span class="identifier-syntax">ct</span><span class="plain-syntax">++; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ct</span><span class="plain-syntax"> >= </span><span class="identifier-syntax">count</span><span class="plain-syntax">) { </span><span class="identifier-syntax">ct</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="identifier-syntax">ssd</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; }</span>
|
|
<span class="plain-syntax"> }</span>
|
|
<span class="plain-syntax"> </span><span class="comment-syntax">rint "Out v=", v, " ct=", ct, " ssd=", sd, "^";</span>
|
|
<span class="plain-syntax"> </span><span class="comment-syntax">rint "Return ", v + ct*base + ssd*base*base, "^";</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> + </span><span class="identifier-syntax">ct</span><span class="plain-syntax">*</span><span class="identifier-syntax">base</span><span class="plain-syntax"> + </span><span class="identifier-syntax">ssd</span><span class="plain-syntax">*</span><span class="identifier-syntax">base</span><span class="plain-syntax">*</span><span class="identifier-syntax">base</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP20" class="paragraph-anchor"></a><b>§20. Rounding. </b>The following rounds a numerical value <span class="extract"><span class="extract-syntax">t1</span></span> to the nearest unit of <span class="extract"><span class="extract-syntax">t2</span></span>;
|
|
for instance, if <span class="extract"><span class="extract-syntax">t2</span></span> is 5 then it rounds to the nearest 5. The name is an
|
|
anachronism, as it's used for all kinds of value.
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">RoundOffValue</span><span class="plain-syntax"> </span><span class="identifier-syntax">t1</span><span class="plain-syntax"> </span><span class="identifier-syntax">t2</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">t1</span><span class="plain-syntax"> >= </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">t1</span><span class="plain-syntax">+</span><span class="identifier-syntax">t2</span><span class="plain-syntax">/2)/</span><span class="identifier-syntax">t2</span><span class="plain-syntax">)*</span><span class="identifier-syntax">t2</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -((-</span><span class="identifier-syntax">t1</span><span class="plain-syntax">+</span><span class="identifier-syntax">t2</span><span class="plain-syntax">/2)/</span><span class="identifier-syntax">t2</span><span class="plain-syntax">)*</span><span class="identifier-syntax">t2</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<p class="commentary firstcommentary"><a id="SP21" class="paragraph-anchor"></a><b>§21. Doing nothing. </b>Surprisingly, this function has a use.
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax">[ </span><span class="identifier-syntax">DoNothing</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
|
|
<span class="plain-syntax">];</span>
|
|
</pre>
|
|
<nav role="progress"><div class="progresscontainer">
|
|
<ul class="progressbar"><li class="progressprev"><a href="S-str.html">❮</a></li><li class="progresssection"><a href="S-dfn.html">dfn</a></li><li class="progresssection"><a href="S-str.html">str</a></li><li class="progresscurrent">utl</li><li class="progresssection"><a href="S-prg.html">prg</a></li><li class="progresssection"><a href="S-mth.html">mth</a></li><li class="progresssection"><a href="S-srt.html">srt</a></li><li class="progresssection"><a href="S-tbl.html">tbl</a></li><li class="progresssection"><a href="S-mst.html">mst</a></li><li class="progresssection"><a href="S-rlb.html">rlb</a></li><li class="progresssection"><a href="S-act.html">act</a></li><li class="progresssection"><a href="S-prn.html">prn</a></li><li class="progresssection"><a href="S-flx.html">flx</a></li><li class="progresssection"><a href="S-blc.html">blc</a></li><li class="progresssection"><a href="S-txt.html">txt</a></li><li class="progresssection"><a href="S-chr.html">chr</a></li><li class="progresssection"><a href="S-rgx.html">rgx</a></li><li class="progresssection"><a href="S-lst.html">lst</a></li><li class="progresssection"><a href="S-cmb.html">cmb</a></li><li class="progresssection"><a href="S-rlt.html">rlt</a></li><li class="progresssection"><a href="S-rlt2.html">rlt2</a></li><li class="progresssection"><a href="S-rtp.html">rtp</a></li><li class="progressnext"><a href="S-prg.html">❯</a></li></ul></div>
|
|
</nav><!--End of weave-->
|
|
|
|
</main>
|
|
</body>
|
|
</html>
|
|
|