mirror of
https://github.com/ganelson/inform.git
synced 2024-07-16 22:14:23 +03:00
2080 lines
117 KiB
HTML
2080 lines
117 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<title>S/md</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<meta http-equiv="Content-Language" content="en-gb">
|
|
<link href="inweb.css" rel="stylesheet" rev="stylesheet" type="text/css">
|
|
</head>
|
|
<body>
|
|
|
|
<!--Weave of 'S/pd' generated by 7-->
|
|
<ul class="crumbs"><li><a href="../webs.html">★</a></li><li><a href="index.html">basicinform 1</a></li><li><b>Phrase Definitions</b></li></ul><p class="purpose">The phrases making up the basic Inform language, and in terms of which all other phrases and rules are defined.</p>
|
|
|
|
<ul class="toc"><li><a href="#SP4">§4. Say phrases</a></li><li><a href="#SP13">§13. Variables</a></li><li><a href="#SP16">§16. Arithmetic</a></li><li><a href="#SP22">§22. Control structures</a></li><li><a href="#SP29">§29. Values</a></li><li><a href="#SP32">§32. Text</a></li><li><a href="#SP37">§37. Adaptive text</a></li><li><a href="#SP38">§38. Data Structures</a></li><li><a href="#SP41">§41. Lists</a></li><li><a href="#SP47">§47. Functional Programming</a></li><li><a href="#SP49">§49. Rulebooks and Activities</a></li><li><a href="#SP53">§53. External Files</a></li></ul><hr class="tocbar">
|
|
|
|
<p class="inwebparagraph"><a id="SP1"></a><b>§1. </b>All phrases of the Inform language itself are defined here. The Standard
|
|
Rules extension adds more, specialised for interactive fiction creation,
|
|
but the bones of the language are here. For example, we will define what
|
|
the plus sign will mean, and how Inform should compile "say N in words",
|
|
where N is a number. Inform has no phrase definitions built in, as such;
|
|
but it does contain assumptions about control structures such as "say ...",
|
|
"repeat ...", "let ...", "otherwise ..." and so on will behave. Those, we
|
|
would not be able to redefine in fundamentally different ways. In most
|
|
respects, though, we are more or less free to define any language we like.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">At first sight, these phrase definitions look little more than simple
|
|
transliterations, and this was one source of early criticism of Inform 7.
|
|
Phrases appeared to have very simplistic definitions, with the natural
|
|
language simply being a verbose description of obviously equivalent C-like
|
|
code. However, the simplicity is misleading, because the definitions below
|
|
tend to conceal where the complexity of the translation process suddenly
|
|
increases. If the preamble includes "(c - condition)", and the definition
|
|
includes the expansion <code class="display"><span class="extract">{c}</span></code>, then the text forming c is translated in a way
|
|
much more profound than any simple substitution process could describe.
|
|
Type-checking also complicates the code produced below, since Inform
|
|
automatically generates the code needed to perform run-time type checking at
|
|
any point where doubt remains as to the phrase definition which must be used.
|
|
</p>
|
|
|
|
<p class="inwebparagraph"><a id="SP2"></a><b>§2. </b>Many of these phrases have what are called inline definitions, written
|
|
using the <code class="display"><span class="extract">(-</span></code> and <code class="display"><span class="extract">-)</span></code> notation. Non-inline phrases are compiled as
|
|
functions, which are then called when they need to be used. For example,
|
|
"To say the magic number: say 17." compiles to a function, and when
|
|
another phrase includes the instruction "say the magic number", that
|
|
instruction compiles a call to this function. But an inline phrase
|
|
instead generates Inter instructions to do something directly. (That
|
|
something may in fact still be just a function call, but not always.)
|
|
The Inter code to be generated is expressed by the contents of the
|
|
definition between the <code class="display"><span class="extract">(-</span></code> and <code class="display"><span class="extract">-)</span></code> markers, and is written in a
|
|
marked-up form of Inform 6 notation. This is much more concise and
|
|
readable than if the Inter code were written out longhand, but it may
|
|
give the misleading impression that Inform inline definitions can only
|
|
produce Inform 6 code. That is not so: they produce Inter code, which
|
|
can then be translated as needed.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">Most of the definitions here also have annotations to positions in the
|
|
main Inform dcumentation: for example, <code class="display"><span class="extract">(documented at phs_s)</span></code>. This has
|
|
no effect on the code compiled, and is used only when Inform generates
|
|
certain problem messages; if the source text misuses the phrase, the problem
|
|
can then give a reference to the relevant documentation. <code class="display"><span class="extract">phs_s</span></code> is a
|
|
typical example of a "documentation token", and is only a label. See the
|
|
source of the Inform documentation for how this markup is done.
|
|
</p>
|
|
|
|
<p class="inwebparagraph"><a id="SP3"></a><b>§3. </b>Unit tests for the phrases below have test case names beginning <code class="display"><span class="extract">BIP-</span></code>,
|
|
which stands for "Basic Inform phrase". In fact, these come in pairs, one for
|
|
each virtual machine we customarily generate code to. For example, <code class="display"><span class="extract">BIP-Say</span></code>
|
|
tests the "say" phrase for the Z-machine target, and <code class="display"><span class="extract">BIP-Say-G</span></code> does the same
|
|
for the Glulx target. But in the commentary below, test cases will be listed
|
|
only once.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">It follows that running <code class="display"><span class="extract">intest -from inform7 BIP-%c+</span></code> will test all of
|
|
these phrases on all platforms, since this regular expression matches all
|
|
test case names beginning with "BIP-".
|
|
</p>
|
|
|
|
<p class="inwebparagraph"><a id="SP4"></a><b>§4. Say phrases. </b>We begin with saying phrases: the very first phrase to exist is the one
|
|
printing a single value — literal text, a number, a time, an object, or
|
|
really almost anything, since the vast majority of kinds in Inform are
|
|
sayable. There used to be separate definitions for saying text, numbers
|
|
and unicode characters here, but they were removed in June 2015 as being
|
|
redundant. Though they did no harm, they made some problem messages longer
|
|
than necessary by obliging them to cite a longer list of possible readings
|
|
of a misread phrase.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">The three inline definitions here neatly demonstrate the three sorts of
|
|
things which appear inside <code class="display"><span class="extract">(-</span></code> and <code class="display"><span class="extract">-)</span></code>. The definition for "To say s",
|
|
which looks more familiar as the "[s]" text substitution, is straightforwardly
|
|
Inform 6 notation. The definition for "To say (something - number) in words"
|
|
is I6 notation except for the <code class="display"><span class="extract">{something}</span></code> part in braces: this expands
|
|
to the value used by the code causing compilation. For example, if the code
|
|
to be compiled is "say 17 in words" then <code class="display"><span class="extract">{something}</span></code> here would expand to
|
|
the constant 17. The definition for "To say (val)" is much more complex than
|
|
I6 notation could convey, and so a more complex escape notation is needed,
|
|
<code class="display"><span class="extract">{-say:val:K}</span></code>, which tells Inform o compile code which will say <code class="display"><span class="extract">val</span></code> with
|
|
whatever method is appropriate to its kind <code class="display"><span class="extract">K</span></code>. For documentation on these
|
|
escape notations, see the core Inform source code.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">The global variable <code class="display"><span class="extract">say__n</span></code> tracks the last number printed. For the "in
|
|
words" definition, we need to set it by hand, since Inform doesn't otherwise
|
|
realise that number-printing is what we are doing here. For definitions of
|
|
functions such as <code class="display"><span class="extract">STextSubstitution</span></code>, see the source for <code class="display"><span class="extract">BasicInformKit</span></code>,
|
|
which is also where <code class="display"><span class="extract">say__n</span></code> is defined.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Say</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Part Three - Phrasebook</span>
|
|
|
|
<span class="plain">Chapter 1 - Saying</span>
|
|
|
|
<span class="plain">Section 1 - Saying Values</span>
|
|
|
|
<span class="plain">To say (val - sayable value of kind K)</span>
|
|
<span class="plain">(documented at ph_say):</span>
|
|
<span class="plain">(- {-say:val:K} -).</span>
|
|
<span class="plain">To say (something - number) in words</span>
|
|
<span class="plain">(documented at phs_numwords):</span>
|
|
<span class="plain">(- print (number) say__n=({something}); -).</span>
|
|
<span class="plain">To say s</span>
|
|
<span class="plain">(documented at phs_s):</span>
|
|
<span class="plain">(- STextSubstitution(); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP5"></a><b>§5. </b>"Showme" is a debugging version of "say" which can print some version of
|
|
the value, and the kind, of just about anything.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Showme</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">To showme (val - value)</span>
|
|
<span class="plain">(documented at ph_showme):</span>
|
|
<span class="plain">(- {-show-me:val} -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP6"></a><b>§6. </b>Objects are the most difficult things to say, because of the elaborate
|
|
apparatus for managing their natural-language representations. In particular,
|
|
we need to say them with a definite or indefinite article, which can either
|
|
be capitalised or not, and as part of that we need to keep track of whether
|
|
they are proper nouns; in languages other than English, there are also gender
|
|
and case to worry about.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">Note that "To say ..." phrases are case sensitive on the first word, so that
|
|
"to say a something" and "to say A something" are different.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">A curiosity of Inform 6's syntax, arising I think mostly from the need to
|
|
save property memory in "Curses" (1993), the work of IF for which Inform 1
|
|
had been created, is that it lacks a <code class="display"><span class="extract">print (A) ...</span></code> statement. The omission
|
|
is made good by using a routine in the template library instead.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-SayName</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 2 - Saying Names</span>
|
|
|
|
<span class="plain">To say a (something - object)</span>
|
|
<span class="plain">(documented at phs_a):</span>
|
|
<span class="plain">(- print (a) {something}; -).</span>
|
|
<span class="plain">To say an (something - object)</span>
|
|
<span class="plain">(documented at phs_a):</span>
|
|
<span class="plain">(- print (a) {something}; -).</span>
|
|
<span class="plain">To say A (something - object)</span>
|
|
<span class="plain">(documented at phs_A):</span>
|
|
<span class="plain">(- CIndefArt({something}); -).</span>
|
|
<span class="plain">To say An (something - object)</span>
|
|
<span class="plain">(documented at phs_A):</span>
|
|
<span class="plain">(- CIndefArt({something}); -).</span>
|
|
<span class="plain">To say the (something - object)</span>
|
|
<span class="plain">(documented at phs_the):</span>
|
|
<span class="plain">(- print (the) {something}; -).</span>
|
|
<span class="plain">To say The (something - object)</span>
|
|
<span class="plain">(documented at phs_The):</span>
|
|
<span class="plain">(- print (The) {something}; -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP7"></a><b>§7. </b>Now some text substitutions which are the equivalent of escape characters.
|
|
(In double-quoted I6 text, the notation for a literal quotation mark is a
|
|
tilde <code class="display"><span class="extract">~</span></code>.) Note the use of the "-- running on" annotation, which tells Inform
|
|
that a text substitution should not cause a new-line.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-SaySpecial</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 3 - Saying Special Characters</span>
|
|
|
|
<span class="plain">To say bracket -- running on</span>
|
|
<span class="plain">(documented at phs_bracket):</span>
|
|
<span class="plain">(- print "["; -).</span>
|
|
<span class="plain">To say close bracket -- running on</span>
|
|
<span class="plain">(documented at phs_closebracket):</span>
|
|
<span class="plain">(- print "]"; -).</span>
|
|
<span class="plain">To say apostrophe/' -- running on</span>
|
|
<span class="plain">(documented at phs_apostrophe):</span>
|
|
<span class="plain">(- print "'"; -).</span>
|
|
<span class="plain">To say quotation mark -- running on</span>
|
|
<span class="plain">(documented at phs_quotemark):</span>
|
|
<span class="plain">(- print "~"; -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP8"></a><b>§8. </b>For an explanation of the paragraph breaking algorithm, see the template
|
|
file "Printing.i6t".
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-SayParagraphing</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 4 - Saying Line and Paragraph Breaks</span>
|
|
|
|
<span class="plain">To say line break -- running on</span>
|
|
<span class="plain">(documented at phs_linebreak):</span>
|
|
<span class="plain">(- new_line; -).</span>
|
|
<span class="plain">To say no line break -- running on</span>
|
|
<span class="plain">(documented at phs_nolinebreak):</span>
|
|
<span class="plain">do nothing.</span>
|
|
<span class="plain">To say conditional paragraph break -- running on</span>
|
|
<span class="plain">(documented at phs_condparabreak):</span>
|
|
<span class="plain">(- DivideParagraphPoint(); -).</span>
|
|
<span class="plain">To say paragraph break -- running on</span>
|
|
<span class="plain">(documented at phs_parabreak):</span>
|
|
<span class="plain">(- DivideParagraphPoint(); new_line; -).</span>
|
|
<span class="plain">To say run paragraph on -- running on</span>
|
|
<span class="plain">(documented at phs_runparaon):</span>
|
|
<span class="plain">(- RunParagraphOn(); -).</span>
|
|
<span class="plain">To decide if a paragraph break is pending</span>
|
|
<span class="plain">(documented at ph_breakpending):</span>
|
|
<span class="plain">(- (say__p) -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP9"></a><b>§9. </b>Now for "[if ...]", which expands into a rather assembly-language-like
|
|
usage of <code class="display"><span class="extract">jump</span></code> statements, I6's form of goto. For instance, the text
|
|
"[if the score is 10]It's ten![otherwise]It's not ten, alas." compiles
|
|
thus:
|
|
</p>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">if (~~(score == 10)) jump L_Say3;</span>
|
|
<span class="plain"> ...</span>
|
|
<span class="plain">jump L_SayX2; .L_Say3;</span>
|
|
<span class="plain"> ...</span>
|
|
<span class="plain">.L_Say4; .L_SayX2;</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph">Though labels actually have local namespaces in I6 routines, we use
|
|
globally unique labels throughout the whole program: compiling the same
|
|
phrase again would involve say labels 5 and 6 and "say exit" label 3.
|
|
This example text demonstrates the reason we <code class="display"><span class="extract">jump</span></code> about, rather than
|
|
making use of <code class="display"><span class="extract">if... else...</span></code> and bracing groups of statements: it is legal
|
|
in I7 either to conclude with or to omit the "[end if]". (If statements
|
|
in I6 compile to jump instructions in any event, and on our virtual
|
|
machines there is no speed penalty for branches.) We also need the same
|
|
definitions to accommodate what amounts to a switch statement. The trickier
|
|
text "[if the score is 10]It's ten![otherwise if the score is 8]It's
|
|
eight?[otherwise]It's not ten, alas." comes out as:
|
|
</p>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">if (~~(score == 10)) jump L_Say5;</span>
|
|
<span class="plain"> ...</span>
|
|
<span class="plain">jump L_SayX3; .L_Say5; if (~~(score == 8)) jump L_Say6;</span>
|
|
<span class="plain"> ...</span>
|
|
<span class="plain">jump L_SayX3; .L_Say6;</span>
|
|
<span class="plain"> ...</span>
|
|
<span class="plain">.L_Say7; .L_SayX3;</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph">In either form of the construct, control passes into at most one of the
|
|
pieces of text. The terminal labels (the two on the final line) are
|
|
automatically generated; often — when there is a simple "otherwise" or
|
|
"end if" to conclude the construct — they are not needed, but labels are
|
|
quick to process in I6, are soon discarded from I6's memory when not needed
|
|
any more, and compile no code.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">We assume in each case that the next say label number to be free is always
|
|
the start of the next block, and that the next say exit label number is always
|
|
the one at the end of the current construct. This is true because Inform does
|
|
not allow "say if" to be nested.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-SayIf</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 5 - Saying If and Otherwise</span>
|
|
|
|
<span class="plain">To say if (c - condition)</span>
|
|
<span class="plain">(documented at phs_if): (-</span>
|
|
<span class="plain">if (~~({c})) jump {-label:Say};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To say unless (c - condition)</span>
|
|
<span class="plain">(documented at phs_unless): (-</span>
|
|
<span class="plain">if ({c}) jump {-label:Say};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To say otherwise/else if (c - condition)</span>
|
|
<span class="plain">(documented at phs_elseif): (-</span>
|
|
<span class="plain">jump {-label:SayX}; .{-label:Say}{-counter-up:Say}; if (~~({c})) jump {-label:Say};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To say otherwise/else unless (c - condition)</span>
|
|
<span class="plain">(documented at phs_elseunless): (-</span>
|
|
<span class="plain">jump {-label:SayX}; .{-label:Say}{-counter-up:Say}; if ({c}) jump {-label:Say};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To say otherwise</span>
|
|
<span class="plain">(documented at phs_otherwise): (-</span>
|
|
<span class="plain">jump {-label:SayX}; .{-label:Say}{-counter-up:Say};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To say else</span>
|
|
<span class="plain">(documented at phs_otherwise): (-</span>
|
|
<span class="plain">jump {-label:SayX}; .{-label:Say}{-counter-up:Say};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To say end if</span>
|
|
<span class="plain">(documented at phs_endif): (-</span>
|
|
<span class="plain">.{-label:Say}{-counter-up:Say}; .{-label:SayX}{-counter-up:SayX};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To say end unless</span>
|
|
<span class="plain">(documented at phs_endunless): (-</span>
|
|
<span class="plain">.{-label:Say}{-counter-up:Say}; .{-label:SayX}{-counter-up:SayX};</span>
|
|
<span class="plain">-).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP10"></a><b>§10. </b>The other control structure: the random variations form of saying. This
|
|
part of the Inform design was in effect contributed by the community: it
|
|
reimplements a form of Jon Ingold's former extension Text Variations, which
|
|
itself built on code going back to the days of I6.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">The head phrase has one of the most complicated definitions suppled with
|
|
Inform, but is actually documented fairly explicitly in the Extensions chapter
|
|
of "Writing with Inform", so we won't repeat all that here. Essentially it
|
|
uses its own allocated cell of storage in an array to remember a state between
|
|
uses, and compiles as a switch statement based on the current state.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-SayOneOf</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 6 - Saying one of</span>
|
|
|
|
<span class="plain">To say one of -- beginning say_one_of (documented at phs_oneof): (-</span>
|
|
<span class="plain">{-counter-makes-array:say_one_of}</span>
|
|
<span class="plain">{-counter-makes-array:say_one_flag}</span>
|
|
<span class="plain">if ({-counter-storage:say_one_flag}-->{-counter:say_one_flag} == false) {</span>
|
|
<span class="plain">{-counter-storage:say_one_of}-->{-counter:say_one_of} = {-final-segment-marker}({-counter-storage:say_one_of}-->{-counter:say_one_of}, {-segment-count});</span>
|
|
<span class="plain">{-counter-storage:say_one_flag}-->{-counter:say_one_flag} = true;</span>
|
|
<span class="plain">}</span>
|
|
<span class="plain">if (say__comp == false) {-counter-storage:say_one_flag}-->{-counter:say_one_flag}{-counter-up:say_one_flag} = false;</span>
|
|
<span class="plain">switch (({-counter-storage:say_one_of}-->{-counter:say_one_of}{-counter-up:say_one_of})%({-segment-count}+1)-1)</span>
|
|
<span class="plain">{-open-brace}</span>
|
|
<span class="plain">0: -).</span>
|
|
<span class="plain">To say or -- continuing say_one_of (documented at phs_or):</span>
|
|
<span class="plain">(- @nop; {-segment-count}: -).</span>
|
|
<span class="plain">To say at random -- ending say_one_of with marker I7_SOO_RAN (documented at phs_random):</span>
|
|
<span class="plain">(- {-close-brace} -).</span>
|
|
<span class="plain">To say purely at random -- ending say_one_of with marker I7_SOO_PAR (documented at phs_purelyrandom):</span>
|
|
<span class="plain">(- {-close-brace} -).</span>
|
|
<span class="plain">To say then at random -- ending say_one_of with marker I7_SOO_TRAN (documented at phs_thenrandom):</span>
|
|
<span class="plain">(- {-close-brace} -).</span>
|
|
<span class="plain">To say then purely at random -- ending say_one_of with marker I7_SOO_TPAR (documented at phs_thenpurelyrandom):</span>
|
|
<span class="plain">(- {-close-brace} -).</span>
|
|
<span class="plain">To say sticky random -- ending say_one_of with marker I7_SOO_STI (documented at phs_sticky):</span>
|
|
<span class="plain">(- {-close-brace} -).</span>
|
|
<span class="plain">To say as decreasingly likely outcomes -- ending say_one_of with marker I7_SOO_TAP (documented at phs_decreasing):</span>
|
|
<span class="plain">(- {-close-brace} -).</span>
|
|
<span class="plain">To say in random order -- ending say_one_of with marker I7_SOO_SHU (documented at phs_order):</span>
|
|
<span class="plain">(- {-close-brace} -).</span>
|
|
<span class="plain">To say cycling -- ending say_one_of with marker I7_SOO_CYC (documented at phs_cycling):</span>
|
|
<span class="plain">(- {-close-brace} -).</span>
|
|
<span class="plain">To say stopping -- ending say_one_of with marker I7_SOO_STOP (documented at phs_stopping):</span>
|
|
<span class="plain">(- {-close-brace} -).</span>
|
|
|
|
<span class="plain">To say first time -- beginning say_first_time (documented at phs_firsttime):</span>
|
|
<span class="plain">(- {-counter-makes-array:say_first_time}</span>
|
|
<span class="plain">if ((say__comp == false) && (({-counter-storage:say_first_time}-->{-counter:say_first_time}{-counter-up:say_first_time})++ == 0)) {-open-brace}</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To say only -- ending say_first_time (documented at phs_firsttime):</span>
|
|
<span class="plain">(- {-close-brace} -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP11"></a><b>§11. </b>Now some visual effects, which may or may not be rendered the way the user
|
|
hopes: that's partly up to the virtual machine, unfortunately.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-SayOneOf</span></code>, though since <code class="display"><span class="extract">intest</span></code> runs on plain text only,
|
|
you may need to run this in the Inform application to be convinced.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 7 - Saying Fonts and Visual Effects</span>
|
|
|
|
<span class="plain">To say bold type -- running on</span>
|
|
<span class="plain">(documented at phs_bold):</span>
|
|
<span class="plain">(- style bold; -).</span>
|
|
<span class="plain">To say italic type -- running on</span>
|
|
<span class="plain">(documented at phs_italic):</span>
|
|
<span class="plain">(- style underline; -).</span>
|
|
<span class="plain">To say roman type -- running on</span>
|
|
<span class="plain">(documented at phs_roman):</span>
|
|
<span class="plain">(- style roman; -).</span>
|
|
<span class="plain">To say fixed letter spacing -- running on</span>
|
|
<span class="plain">(documented at phs_fixedspacing):</span>
|
|
<span class="plain">(- font off; -).</span>
|
|
<span class="plain">To say variable letter spacing -- running on</span>
|
|
<span class="plain">(documented at phs_varspacing):</span>
|
|
<span class="plain">(- font on; -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP12"></a><b>§12. </b>These are lists in the sense of the "list of" kind of value constructor, and
|
|
the first two phrases here might list any values, not just objects.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-SayLists</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 8 - Saying Lists of Values</span>
|
|
|
|
<span class="plain">To say (L - a list of values) in brace notation</span>
|
|
<span class="plain">(documented at phs_listbraced):</span>
|
|
<span class="plain">(- LIST_OF_TY_Say({-by-reference:L}, 1); -).</span>
|
|
<span class="plain">To say (L - a list of objects) with definite articles</span>
|
|
<span class="plain">(documented at phs_listdef):</span>
|
|
<span class="plain">(- LIST_OF_TY_Say({-by-reference:L}, 2); -).</span>
|
|
<span class="plain">To say (L - a list of objects) with indefinite articles</span>
|
|
<span class="plain">(documented at phs_listindef):</span>
|
|
<span class="plain">(- LIST_OF_TY_Say({-by-reference:L}, 3); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP13"></a><b>§13. Variables. </b>The "now" phrase can do an extraordinary range of things, and is more or
|
|
less a genie granting one wish.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">The "whether or not" phrase exists only to convert a condition to a value,
|
|
and is needed because I7 does not silently cast from one to the other in
|
|
the way that C would.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Now</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Chapter 2 - Conditions and Variables</span>
|
|
|
|
<span class="plain">Section 1 - Conditions</span>
|
|
|
|
<span class="plain">To now (cn - condition)</span>
|
|
<span class="plain">(documented at ph_now):</span>
|
|
<span class="plain">(- {cn} -).</span>
|
|
<span class="plain">To decide what truth state is whether or not (C - condition)</span>
|
|
<span class="plain">(documented at ph_whether):</span>
|
|
<span class="plain">(- ({C}) -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP14"></a><b>§14. </b>Assignment is probably the most difficult thing the type-checker has to
|
|
cope with, since "let" has to work when applied to both unknown names (it
|
|
creates a new variable) and existing ones (kind of value permitting). There
|
|
are also four different ways to create with "let", and two to use
|
|
existing variables. Note that the "given by" forms are not strictly
|
|
speaking assignments at all; the value placed in <code class="display"><span class="extract">t</span></code> is found by solving
|
|
the equation <code class="display"><span class="extract">Q</span></code>. This does require special typechecking, but of a
|
|
different kind to that requested by "(assignment operation)". All of which
|
|
makes the "To let" section here only slightly shorter than John Galsworthy's
|
|
Forsyte novel of the same name.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Let</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 2 - Assigning Temporary Variables</span>
|
|
|
|
<span class="plain">To let (t - nonexisting variable) be (u - value)</span>
|
|
<span class="plain">(assignment operation)</span>
|
|
<span class="plain">(documented at ph_let): (-</span>
|
|
<span class="plain">{-unprotect:t}</span>
|
|
<span class="plain">{-copy:t:u}</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To let (t - nonexisting variable) be (u - name of kind of value)</span>
|
|
<span class="plain">(assignment operation)</span>
|
|
<span class="plain">(documented at ph_letdefault): (-</span>
|
|
<span class="plain">{-unprotect:t}</span>
|
|
<span class="plain">{-initialise:t}</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To let (t - nonexisting variable) be (u - description of relations of values</span>
|
|
<span class="plain">of kind K to values of kind L)</span>
|
|
<span class="plain">(assignment operation)</span>
|
|
<span class="plain">(documented at ph_letrelation): (-</span>
|
|
<span class="plain">{-unprotect:t}</span>
|
|
<span class="plain">{-initialise:t}</span>
|
|
<span class="plain">{-now-matches-description:t:u};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To let (t - nonexisting variable) be given by (Q - equation name)</span>
|
|
<span class="plain">(documented at ph_letequation): (-</span>
|
|
<span class="plain">{-unprotect:t}</span>
|
|
<span class="plain">{-primitive-definition:solve-equation};</span>
|
|
<span class="plain">-).</span>
|
|
|
|
<span class="plain">To let (t - existing variable) be (u - value)</span>
|
|
<span class="plain">(assignment operation)</span>
|
|
<span class="plain">(documented at ph_let): (-</span>
|
|
<span class="plain">{-copy:t:u}</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To let (t - existing variable) be given by (Q - equation name)</span>
|
|
<span class="plain">(documented at ph_letequation): (-</span>
|
|
<span class="plain">{-primitive-definition:solve-equation};</span>
|
|
<span class="plain">-).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP15"></a><b>§15. </b>It is not explicit in the following definitions that Inform should typecheck
|
|
that the values held by these storage objects can be incremented or decremented
|
|
(as an object, say, cannot, but a number can): Inform nevertheless contains
|
|
code which does this.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Increase</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 3 - Increase and Decrease</span>
|
|
|
|
<span class="plain">To increase (S - storage) by (w - value)</span>
|
|
<span class="plain">(assignment operation)</span>
|
|
<span class="plain">(documented at ph_increase): (-</span>
|
|
<span class="plain">{-copy:S:+w};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To decrease (S - storage) by (w - value)</span>
|
|
<span class="plain">(assignment operation)</span>
|
|
<span class="plain">(documented at ph_decrease): (-</span>
|
|
<span class="plain">{-copy:S:-w};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To increment (S - storage)</span>
|
|
<span class="plain">(documented at ph_increment): (-</span>
|
|
<span class="plain">{-copy:S:+};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To decrement (S - storage)</span>
|
|
<span class="plain">(documented at ph_decrement): (-</span>
|
|
<span class="plain">{-copy:S:-};</span>
|
|
<span class="plain">-).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP16"></a><b>§16. Arithmetic. </b>There are nine arithmetic operations, internally numbered 0 upwards, and
|
|
given verbal forms below. These are handled unusually in the type-checker
|
|
because they need to be more polymorphic than most phrases: Inform uses
|
|
dimension-checking to determine the kind of value resulting. (Thus a
|
|
height times a number is another height, and so on.)
|
|
</p>
|
|
|
|
<p class="inwebparagraph">The totalling code (12) is not structly to do with arithmetic in the same
|
|
way, but it's needed to flag the phrase for the Inform typechecker's special
|
|
attention.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-ArithmeticOperations</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Chapter 2 - Arithmetic</span>
|
|
|
|
<span class="plain">Section 1 - Arithmetic Operations</span>
|
|
|
|
<span class="plain">To decide which arithmetic value is (X - arithmetic value) + (Y - arithmetic value)</span>
|
|
<span class="plain">(arithmetic operation 0)</span>
|
|
<span class="plain">(documented at ph_plus):</span>
|
|
<span class="plain">(- ({-arithmetic-operation:X:Y}) -).</span>
|
|
<span class="plain">To decide which arithmetic value is (X - arithmetic value) plus (Y - arithmetic value)</span>
|
|
<span class="plain">(arithmetic operation 0)</span>
|
|
<span class="plain">(documented at ph_plus):</span>
|
|
<span class="plain">(- ({-arithmetic-operation:X:Y}) -).</span>
|
|
<span class="plain">To decide which arithmetic value is (X - arithmetic value) - (Y - arithmetic value)</span>
|
|
<span class="plain">(arithmetic operation 1)</span>
|
|
<span class="plain">(documented at ph_minus):</span>
|
|
<span class="plain">(- ({-arithmetic-operation:X:Y}) -).</span>
|
|
<span class="plain">To decide which arithmetic value is (X - arithmetic value) minus (Y - arithmetic value)</span>
|
|
<span class="plain">(arithmetic operation 1)</span>
|
|
<span class="plain">(documented at ph_minus):</span>
|
|
<span class="plain">(- ({-arithmetic-operation:X:Y}) -).</span>
|
|
<span class="plain">To decide which arithmetic value is (X - arithmetic value) * (Y - arithmetic value)</span>
|
|
<span class="plain">(arithmetic operation 2)</span>
|
|
<span class="plain">(documented at ph_times):</span>
|
|
<span class="plain">(- ({-arithmetic-operation:X:Y}) -).</span>
|
|
<span class="plain">To decide which arithmetic value is (X - arithmetic value) times (Y - arithmetic value)</span>
|
|
<span class="plain">(arithmetic operation 2)</span>
|
|
<span class="plain">(documented at ph_times):</span>
|
|
<span class="plain">(- ({-arithmetic-operation:X:Y}) -).</span>
|
|
<span class="plain">To decide which arithmetic value is (X - arithmetic value) multiplied by (Y - arithmetic value)</span>
|
|
<span class="plain">(arithmetic operation 2)</span>
|
|
<span class="plain">(documented at ph_times):</span>
|
|
<span class="plain">(- ({-arithmetic-operation:X:Y}) -).</span>
|
|
<span class="plain">To decide which arithmetic value is (X - arithmetic value) / (Y - arithmetic value)</span>
|
|
<span class="plain">(arithmetic operation 3)</span>
|
|
<span class="plain">(documented at ph_divide):</span>
|
|
<span class="plain">(- ({-arithmetic-operation:X:Y}) -).</span>
|
|
<span class="plain">To decide which arithmetic value is (X - arithmetic value) divided by (Y - arithmetic value)</span>
|
|
<span class="plain">(arithmetic operation 3)</span>
|
|
<span class="plain">(documented at ph_divide):</span>
|
|
<span class="plain">(- ({-arithmetic-operation:X:Y}) -).</span>
|
|
<span class="plain">To decide which arithmetic value is remainder after dividing (X - arithmetic value)</span>
|
|
<span class="plain">by (Y - arithmetic value)</span>
|
|
<span class="plain">(arithmetic operation 4)</span>
|
|
<span class="plain">(documented at ph_remainder):</span>
|
|
<span class="plain">(- ({-arithmetic-operation:X:Y}) -).</span>
|
|
<span class="plain">To decide which arithmetic value is (X - arithmetic value) to the nearest (Y - arithmetic value)</span>
|
|
<span class="plain">(arithmetic operation 5)</span>
|
|
<span class="plain">(documented at ph_nearest):</span>
|
|
<span class="plain">(- ({-arithmetic-operation:X:Y}) -).</span>
|
|
<span class="plain">To decide which arithmetic value is the square root of (X - arithmetic value)</span>
|
|
<span class="plain">(arithmetic operation 6)</span>
|
|
<span class="plain">(documented at ph_squareroot):</span>
|
|
<span class="plain">(- ({-arithmetic-operation:X}) -).</span>
|
|
<span class="plain">To decide which arithmetic value is the cube root of (X - arithmetic value)</span>
|
|
<span class="plain">(arithmetic operation 8)</span>
|
|
<span class="plain">(documented at ph_cuberoot):</span>
|
|
<span class="plain">(- ({-arithmetic-operation:X}) -).</span>
|
|
<span class="plain">To decide which arithmetic value is total (p - arithmetic value valued property)</span>
|
|
<span class="plain">of (S - description of values)</span>
|
|
<span class="plain">(arithmetic operation 12)</span>
|
|
<span class="plain">(documented at ph_total):</span>
|
|
<span class="plain">(- {-primitive-definition:total-of} -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP17"></a><b>§17. </b>Real numbers are not available in the Z-machine, but they are likely to
|
|
be available everywhere else, i.e., on any other platform Inform may target
|
|
in future.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-SayRealNumbers-G</span></code>, which has no Z-machine counterpart.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 2 - Saying Real Numbers (not for Z-machine)</span>
|
|
|
|
<span class="plain">To say (R - a real number) to (N - number) decimal places</span>
|
|
<span class="plain">(documented at phs_realplaces):</span>
|
|
<span class="plain">(- Float({R}, {N}); -).</span>
|
|
<span class="plain">To say (R - a real number) in decimal notation</span>
|
|
<span class="plain">(documented at phs_decimal):</span>
|
|
<span class="plain">(- FloatDec({R}); -).</span>
|
|
<span class="plain">To say (R - a real number) to (N - number) decimal places in decimal notation</span>
|
|
<span class="plain">(documented at phs_decimalplaces):</span>
|
|
<span class="plain">(- FloatDec({R}, {N}); -).</span>
|
|
<span class="plain">To say (R - a real number) in scientific notation</span>
|
|
<span class="plain">(documented at phs_scientific):</span>
|
|
<span class="plain">(- FloatExp({R}); -).</span>
|
|
<span class="plain">To say (R - a real number) to (N - number) decimal places in scientific notation</span>
|
|
<span class="plain">(documented at phs_scientificplaces):</span>
|
|
<span class="plain">(- FloatExp({R}, {N}); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP18"></a><b>§18. </b>A number of miscellaneous mathematical functions follow, for real
|
|
numbers only; these are tested as part of <code class="display"><span class="extract">BIP-ArithmeticOperations-G</span></code>,
|
|
already mentioned above. Note that we do not need to define real versions
|
|
of addition, multiplication and so on: the above definitions are polymorphic
|
|
enough to have done that already.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 3 - Real Arithmetic (not for Z-machine)</span>
|
|
|
|
<span class="plain">To decide which real number is the reciprocal of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_reciprocal):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Reciprocal({R}) -).</span>
|
|
<span class="plain">To decide which real number is the absolute value of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_absolutevalue)</span>
|
|
<span class="plain">(this is the abs function):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Abs({R}) -).</span>
|
|
<span class="plain">To decide which real number is the real square root of (R - a real number)</span>
|
|
<span class="plain">(arithmetic operation 7)</span>
|
|
<span class="plain">(documented at ph_realsquareroot)</span>
|
|
<span class="plain">(this is the root function inverse to rsqr):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Root({R}) -).</span>
|
|
<span class="plain">To decide which real number is the real square of (R - a real number)</span>
|
|
<span class="plain">(this is the rsqr function inverse to root):</span>
|
|
<span class="plain">let x be given by x = R^2 where x is a real number;</span>
|
|
<span class="plain">decide on x.</span>
|
|
<span class="plain">To decide which real number is the ceiling of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_ceiling)</span>
|
|
<span class="plain">(this is the ceiling function):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Ceiling({R}) -).</span>
|
|
<span class="plain">To decide which real number is the floor of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_floor)</span>
|
|
<span class="plain">(this is the floor function):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Floor({R}) -).</span>
|
|
<span class="plain">To decide which number is (R - a real number) to the nearest whole number</span>
|
|
<span class="plain">(documented at ph_nearestwholenumber)</span>
|
|
<span class="plain">(this is the int function):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_to_NUMBER_TY({R}) -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP19"></a><b>§19. </b>And these are tested in <code class="display"><span class="extract">BIP-Exponentials-G</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 4 - Exponential Functions (not for Z-machine)</span>
|
|
|
|
<span class="plain">To decide which real number is the natural/-- logarithm of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_logarithm)</span>
|
|
<span class="plain">(this is the log function inverse to exp):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Log({R}) -).</span>
|
|
<span class="plain">To decide which real number is the logarithm to base (N - a number) of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_logarithmto):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_BLog({R}, {N}) -).</span>
|
|
<span class="plain">To decide which real number is the exponential of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_exp)</span>
|
|
<span class="plain">(this is the exp function inverse to log):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Exp({R}) -).</span>
|
|
<span class="plain">To decide which real number is (R - a real number) to the power (P - a real number)</span>
|
|
<span class="plain">(documented at ph_power):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Pow({R}, {P}) -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP20"></a><b>§20. </b>And these are tested in <code class="display"><span class="extract">BIP-Trigonometry-G</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 5 - Trigonometric Functions (not for Z-machine)</span>
|
|
|
|
<span class="plain">To decide which real number is (R - a real number) degrees</span>
|
|
<span class="plain">(documented at ph_degrees):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Times({R}, $+0.0174532925) -).</span>
|
|
|
|
<span class="plain">To decide which real number is the sine of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_sine)</span>
|
|
<span class="plain">(this is the sin function inverse to arcsin):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Sin({R}) -).</span>
|
|
<span class="plain">To decide which real number is the cosine of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_cosine)</span>
|
|
<span class="plain">(this is the cos function inverse to arccos):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Cos({R}) -).</span>
|
|
<span class="plain">To decide which real number is the tangent of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_tangent)</span>
|
|
<span class="plain">(this is the tan function inverse to arctan):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Tan({R}) -).</span>
|
|
<span class="plain">To decide which real number is the arcsine of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_arcsine)</span>
|
|
<span class="plain">(this is the arcsin function inverse to sin):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Arcsin({R}) -).</span>
|
|
<span class="plain">To decide which real number is the arccosine of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_arccosine)</span>
|
|
<span class="plain">(this is the arccos function inverse to cos):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Arccos({R}) -).</span>
|
|
<span class="plain">To decide which real number is the arctangent of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_arctangent)</span>
|
|
<span class="plain">(this is the arctan function inverse to tan):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Arctan({R}) -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP21"></a><b>§21. </b>And these are tested in <code class="display"><span class="extract">BIP-Hyperbolics-G</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 6 - Trigonometric Functions (not for Z-machine)</span>
|
|
|
|
<span class="plain">To decide which real number is the hyperbolic sine of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_hyperbolicsine)</span>
|
|
<span class="plain">(this is the sinh function inverse to arcsinh):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Sinh({R}) -).</span>
|
|
<span class="plain">To decide which real number is the hyperbolic cosine of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_hyperboliccosine)</span>
|
|
<span class="plain">(this is the cosh function inverse to arccosh):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Cosh({R}) -).</span>
|
|
<span class="plain">To decide which real number is the hyperbolic tangent of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_hyperbolictangent)</span>
|
|
<span class="plain">(this is the tanh function inverse to arctanh):</span>
|
|
<span class="plain">(- REAL_NUMBER_TY_Tanh({R}) -).</span>
|
|
<span class="plain">To decide which real number is the hyperbolic arcsine of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_hyperbolicarcsine)</span>
|
|
<span class="plain">(this is the arcsinh function inverse to sinh):</span>
|
|
<span class="plain">let x be given by x = log(R + root(R^2 + 1)) where x is a real number;</span>
|
|
<span class="plain">decide on x.</span>
|
|
<span class="plain">To decide which real number is the hyperbolic arccosine of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_hyperbolicarccosine)</span>
|
|
<span class="plain">(this is the arccosh function inverse to cosh):</span>
|
|
<span class="plain">let x be given by x = log(R + root(R^2 - 1)) where x is a real number;</span>
|
|
<span class="plain">decide on x.</span>
|
|
<span class="plain">To decide which real number is the hyperbolic arctangent of (R - a real number)</span>
|
|
<span class="plain">(documented at ph_hyperbolicarctangent)</span>
|
|
<span class="plain">(this is the arctanh function inverse to tanh):</span>
|
|
<span class="plain">let x be given by x = 0.5*(log(1+R) - log(1-R)) where x is a real number;</span>
|
|
<span class="plain">decide on x.</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP22"></a><b>§22. Control structures. </b>The term "control structure" conjures up the thought of conditionals and loops,
|
|
and we'll get to those, but we'll begin with the equivalent of the C language's
|
|
<code class="display"><span class="extract">return</span></code> statement: ending a function call with some value as an outcome.
|
|
Inform calls this "deciding" something, since in Inform programs functions
|
|
returning values are usually quite functional: that is, their point is what
|
|
value they return, rather than the side-effects of what they did.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">Note that returning a value has to invoke the type-checker to ensure that
|
|
the return value matches the kind of value expected. This certainly rejects
|
|
the phrase if it's used in a definition which isn't meant to be deciding
|
|
a value at all, so an "in... only" clause is not needed.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">The IF-form of Inform allows the antique syntaxes "yes" and "no" as
|
|
synonyms for "decide yes" and "decide no"; these are not present in Basic
|
|
Inform, and are defined in the Standard Rules (and only to keep old source
|
|
text working).
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Decide</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Chapter 3 - Control</span>
|
|
|
|
<span class="plain">Section 1 - Deciding Outcomes</span>
|
|
|
|
<span class="plain">To decide yes</span>
|
|
<span class="plain">(documented at ph_yes):</span>
|
|
<span class="plain">(- rtrue; -) - in to decide if only.</span>
|
|
<span class="plain">To decide no</span>
|
|
<span class="plain">(documented at ph_no):</span>
|
|
<span class="plain">(- rfalse; -) - in to decide if only.</span>
|
|
|
|
<span class="plain">To stop (documented at ph_stop):</span>
|
|
<span class="plain">(- rtrue; -) - in to only.</span>
|
|
|
|
<span class="plain">To decide on (something - value)</span>
|
|
<span class="plain">(documented at ph_decideon):</span>
|
|
<span class="plain">(- return {-return-value:something}; -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP23"></a><b>§23. </b>While "unless" is supposed to be exactly like "if" but with the reversed
|
|
sense of the condition, that isn't quite true. For example, there is no
|
|
"unless ... then ...": logical it might be, English it is not.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">The switch form of "if" is subtly different, and here again "unless" is
|
|
not allowed in its place.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">As with some other control structures, the definitions here are somewhat
|
|
partial, and made up for by direct code in the compiler. (There's a limit to
|
|
how much a general syntax for phrases can encode control phrases.)
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-If</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 2 - If and Unless</span>
|
|
|
|
<span class="plain">To if (c - condition) begin -- end conditional</span>
|
|
<span class="plain">(documented at ph_if):</span>
|
|
<span class="plain">(- {c} -).</span>
|
|
<span class="plain">To unless (c - condition) begin -- end conditional</span>
|
|
<span class="plain">(documented at ph_unless):</span>
|
|
<span class="plain">(- (~~{c}) -).</span>
|
|
<span class="plain">To if (V - value) is begin -- end conditional</span>
|
|
<span class="plain">(documented at ph_switch):</span>
|
|
<span class="plain">(- -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP24"></a><b>§24. </b>"Do nothing" is a curious feature for a high-level programming language (C,
|
|
for example, does not have a NOP function); it entered Inform in the earliest
|
|
days, when it was useful mainly when natural language syntax had painted users
|
|
into a corner. (In the examples, it used to be used when conditions were
|
|
awkward to negate — if condition, do nothing, otherwise blah blah blah — but
|
|
the creation of "unless" made it possible to remove most of the "do
|
|
nothing"s.) It is now hardly ever useful.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">To do nothing (documented at ph_nothing):</span>
|
|
<span class="plain">(- ; -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP25"></a><b>§25. </b>After all that, the while loop is simplicity itself. Perhaps the presence
|
|
of "unless" for "if" argues for a similarly negated form, "until" for
|
|
"while", but users haven't yet petitioned for this.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Loops</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 3 - While and Repeat</span>
|
|
|
|
<span class="plain">To while (c - condition) begin -- end loop</span>
|
|
<span class="plain">(documented at ph_while):</span>
|
|
<span class="plain">(- while {c} -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP26"></a><b>§26. </b>The repeat loop looks like a single construction, but isn't, because the
|
|
range can be given in four fundamentally different ways (and the loop variable
|
|
then has a different kind of value accordingly). First, the equivalents of
|
|
BASIC's <code class="display"><span class="extract">for</span></code> loop and of Inform 6's <code class="display"><span class="extract">objectloop</span></code>, respectively:
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">To repeat with (loopvar - nonexisting K variable)</span>
|
|
<span class="plain">running from (v - arithmetic value of kind K) to (w - K) begin -- end loop</span>
|
|
<span class="plain">(documented at ph_repeat):</span>
|
|
<span class="plain">(- for ({loopvar}={v}: {loopvar}<={w}: {loopvar}++) -).</span>
|
|
<span class="plain">To repeat with (loopvar - nonexisting K variable)</span>
|
|
<span class="plain">running from (v - enumerated value of kind K) to (w - K) begin -- end loop</span>
|
|
<span class="plain">(documented at ph_repeat):</span>
|
|
<span class="plain">(- for ({loopvar}={v}: {loopvar}<={w}: {loopvar}++) -).</span>
|
|
<span class="plain">To repeat with (loopvar - nonexisting K variable)</span>
|
|
<span class="plain">running through (OS - description of values of kind K) begin -- end loop</span>
|
|
<span class="plain">(documented at ph_runthrough):</span>
|
|
<span class="plain">(- {-primitive-definition:repeat-through} -).</span>
|
|
<span class="plain">To repeat with (loopvar - nonexisting object variable)</span>
|
|
<span class="plain">running through (L - list of values) begin -- end loop</span>
|
|
<span class="plain">(documented at ph_repeatlist):</span>
|
|
<span class="plain">(- {-primitive-definition:repeat-through-list} -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP27"></a><b>§27. </b>The following are all repeats where the range is the set of rows of a table,
|
|
taken in some order, and the repeat variable — though it does exist — is
|
|
never specified since the relevant row is instead the one selected during
|
|
each iteration of the loop.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">To repeat through (T - table name) begin -- end loop</span>
|
|
<span class="plain">(documented at ph_repeattable): (-</span>
|
|
<span class="plain">@push {-my:ct_0}; @push {-my:ct_1};</span>
|
|
<span class="plain">for ({-my:1}={T}, {-my:2}=1, ct_0={-my:1}, ct_1={-my:2}:</span>
|
|
<span class="plain">{-my:2}<=TableRows({-my:1}):</span>
|
|
<span class="plain">{-my:2}++, ct_0={-my:1}, ct_1={-my:2})</span>
|
|
<span class="plain">if (TableRowIsBlank(ct_0, ct_1)==false)</span>
|
|
<span class="plain">{-block}</span>
|
|
<span class="plain">@pull {-my:ct_1}; @pull {-my:ct_0};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To repeat through (T - table name) in reverse order begin -- end loop</span>
|
|
<span class="plain">(documented at ph_repeattablereverse): (-</span>
|
|
<span class="plain">@push {-my:ct_0}; @push {-my:ct_1};</span>
|
|
<span class="plain">for ({-my:1}={T}, {-my:2}=TableRows({-my:1}), ct_0={-my:1}, ct_1={-my:2}:</span>
|
|
<span class="plain">{-my:2}>=1:</span>
|
|
<span class="plain">{-my:2}--, ct_0={-my:1}, ct_1={-my:2})</span>
|
|
<span class="plain">if (TableRowIsBlank(ct_0, ct_1)==false)</span>
|
|
<span class="plain">{-block}</span>
|
|
<span class="plain">@pull {-my:ct_1}; @pull {-my:ct_0};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To repeat through (T - table name) in (TC - table column) order begin -- end loop</span>
|
|
<span class="plain">(documented at ph_repeattablecol): (-</span>
|
|
<span class="plain">@push {-my:ct_0}; @push {-my:ct_1};</span>
|
|
<span class="plain">for ({-my:1}={T}, {-my:2}=TableNextRow({-my:1}, {TC}, 0, 1), ct_0={-my:1}, ct_1={-my:2}:</span>
|
|
<span class="plain">{-my:2}~=0:</span>
|
|
<span class="plain">{-my:2}=TableNextRow({-my:1}, {TC}, {-my:2}, 1), ct_0={-my:1}, ct_1={-my:2})</span>
|
|
<span class="plain">{-block}</span>
|
|
<span class="plain">@pull {-my:ct_1}; @pull {-my:ct_0};</span>
|
|
<span class="plain">-).</span>
|
|
<span class="plain">To repeat through (T - table name) in reverse (TC - table column) order begin -- end loop</span>
|
|
<span class="plain">(documented at ph_repeattablecolreverse): (-</span>
|
|
<span class="plain">@push {-my:ct_0}; @push {-my:ct_1};</span>
|
|
<span class="plain">for ({-my:1}={T}, {-my:2}=TableNextRow({-my:1}, {TC}, 0, -1), ct_0={-my:1}, ct_1={-my:2}:</span>
|
|
<span class="plain">{-my:2}~=0:</span>
|
|
<span class="plain">{-my:2}=TableNextRow({-my:1}, {TC}, {-my:2}, -1), ct_0={-my:1}, ct_1={-my:2})</span>
|
|
<span class="plain">{-block}</span>
|
|
<span class="plain">@pull {-my:ct_1}; @pull {-my:ct_0};</span>
|
|
<span class="plain">-).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP28"></a><b>§28. </b>The equivalent of <code class="display"><span class="extract">break</span></code> or <code class="display"><span class="extract">continue</span></code> in C or I6, or of <code class="display"><span class="extract">last</span></code> or <code class="display"><span class="extract">next</span></code>
|
|
in Perl. Here "in loop" means "in any of the forms of while or repeat".
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Break</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 4 - Loop Flow</span>
|
|
|
|
<span class="plain">To break -- in loop</span>
|
|
<span class="plain">(documented at ph_break):</span>
|
|
<span class="plain">(- {-primitive-definition:break} -).</span>
|
|
<span class="plain">To next -- in loop</span>
|
|
<span class="plain">(documented at ph_next):</span>
|
|
<span class="plain">(- continue; -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP29"></a><b>§29. Values. </b>Some of the things we can do with enumerations, others being listed under
|
|
randomness below.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Enumerations</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Chapter 4 - Values</span>
|
|
|
|
<span class="plain">Section 1 - Enumerations</span>
|
|
|
|
<span class="plain">To decide which number is number of (S - description of values)</span>
|
|
<span class="plain">(documented at ph_numberof):</span>
|
|
<span class="plain">(- {-primitive-definition:number-of} -).</span>
|
|
<span class="plain">To decide which K is (name of kind of enumerated value K) after (X - K)</span>
|
|
<span class="plain">(documented at ph_enumafter):</span>
|
|
<span class="plain">(- {-next-routine:K}({X}) -).</span>
|
|
<span class="plain">To decide which K is (name of kind of enumerated value K) before (X - K)</span>
|
|
<span class="plain">(documented at ph_enumbefore):</span>
|
|
<span class="plain">(- {-previous-routine:K}({X}) -).</span>
|
|
<span class="plain">To decide which K is the first value of (name of kind of enumerated value K)</span>
|
|
<span class="plain">(documented at ph_enumfirst):</span>
|
|
<span class="plain">decide on the default value of K.</span>
|
|
<span class="plain">To decide which K is the last value of (name of kind of enumerated value K)</span>
|
|
<span class="plain">(documented at ph_enumlast):</span>
|
|
<span class="plain">decide on K before the default value of K.</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP30"></a><b>§30. </b>Random numbers and random items chosen from sets of objects matching a
|
|
given description ("a random closed door").
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Randomness</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 2 - Randomness</span>
|
|
|
|
<span class="plain">To decide which K is a/-- random (S - description of values of kind K)</span>
|
|
<span class="plain">(documented at ph_randomdesc):</span>
|
|
<span class="plain">(- {-primitive-definition:random-of} -).</span>
|
|
<span class="plain">To decide which K is a random (name of kind of arithmetic value K) between (first value - K) and (second value - K)</span>
|
|
<span class="plain">(documented at ph_randombetween):</span>
|
|
<span class="plain">(- {-ranger-routine:K}({first value}, {second value}) -).</span>
|
|
<span class="plain">To decide which K is a random (name of kind of arithmetic value K) from (first value - K) to (second value - K)</span>
|
|
<span class="plain">(documented at ph_randombetween):</span>
|
|
<span class="plain">(- {-ranger-routine:K}({first value}, {second value}) -).</span>
|
|
<span class="plain">To decide which K is a random (name of kind of enumerated value K) between (first value - K) and (second value - K)</span>
|
|
<span class="plain">(documented at ph_randombetween):</span>
|
|
<span class="plain">(- {-ranger-routine:K}({first value}, {second value}) -).</span>
|
|
<span class="plain">To decide which K is a random (name of kind of enumerated value K) from (first value - K) to (second value - K)</span>
|
|
<span class="plain">(documented at ph_randombetween):</span>
|
|
<span class="plain">(- {-ranger-routine:K}({first value}, {second value}) -).</span>
|
|
<span class="plain">To decide whether a random chance of (N - number) in (M - number) succeeds</span>
|
|
<span class="plain">(documented at ph_randomchance):</span>
|
|
<span class="plain">(- (GenerateRandomNumber(1, {M}) <= {N}) -).</span>
|
|
<span class="plain">To seed the random-number generator with (N - number)</span>
|
|
<span class="plain">(documented at ph_seed):</span>
|
|
<span class="plain">(- VM_Seed_RNG({N}); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP31"></a><b>§31. </b>A novel feature of Inform is that there is a default value of any kind: fpr
|
|
example, it is 0 for a number, or the empty text for text. When Inform compiles
|
|
a value of a given kind but isn't told what value to compile, it always
|
|
chooses the default, which is why the following definition works.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-DefaultValues</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 3 - Default Values</span>
|
|
|
|
<span class="plain">To decide what K is the default value of (V - name of kind of value of kind K)</span>
|
|
<span class="plain">(documented at ph_defaultvalue):</span>
|
|
<span class="plain">(- {-new:K} -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP32"></a><b>§32. Text. </b>Inform programs swim in a sea of texts, and most of the ways to make text
|
|
involve substitutions; so phrases to manipulate text are nice to have, but
|
|
are bonuses rather than being the essentials.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">As repetitive as the following is, it's much simpler and less prone to
|
|
possible namespace trouble if we don't define kinds of value for the different
|
|
structural levels of text (character, word, punctuated word, etc.).
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Texts</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Chapter 5 - Text</span>
|
|
|
|
<span class="plain">Section 1 - Breaking down text</span>
|
|
|
|
<span class="plain">To decide what number is the number of characters in (T - text)</span>
|
|
<span class="plain">(documented at ph_numchars):</span>
|
|
<span class="plain">(- TEXT_TY_BlobAccess({-by-reference:T}, CHR_BLOB) -).</span>
|
|
<span class="plain">To decide what number is the number of words in (T - text)</span>
|
|
<span class="plain">(documented at ph_numwords):</span>
|
|
<span class="plain">(- TEXT_TY_BlobAccess({-by-reference:T}, WORD_BLOB) -).</span>
|
|
<span class="plain">To decide what number is the number of punctuated words in (T - text)</span>
|
|
<span class="plain">(documented at ph_numpwords):</span>
|
|
<span class="plain">(- TEXT_TY_BlobAccess({-by-reference:T}, PWORD_BLOB) -).</span>
|
|
<span class="plain">To decide what number is the number of unpunctuated words in (T - text)</span>
|
|
<span class="plain">(documented at ph_numupwords):</span>
|
|
<span class="plain">(- TEXT_TY_BlobAccess({-by-reference:T}, UWORD_BLOB) -).</span>
|
|
<span class="plain">To decide what number is the number of lines in (T - text)</span>
|
|
<span class="plain">(documented at ph_numlines):</span>
|
|
<span class="plain">(- TEXT_TY_BlobAccess({-by-reference:T}, LINE_BLOB) -).</span>
|
|
<span class="plain">To decide what number is the number of paragraphs in (T - text)</span>
|
|
<span class="plain">(documented at ph_numparas):</span>
|
|
<span class="plain">(- TEXT_TY_BlobAccess({-by-reference:T}, PARA_BLOB) -).</span>
|
|
|
|
<span class="plain">To decide what text is character number (N - a number) in (T - text)</span>
|
|
<span class="plain">(documented at ph_charnum):</span>
|
|
<span class="plain">(- TEXT_TY_GetBlob({-new:text}, {-by-reference:T}, {N}, CHR_BLOB) -).</span>
|
|
<span class="plain">To decide what text is word number (N - a number) in (T - text)</span>
|
|
<span class="plain">(documented at ph_wordnum):</span>
|
|
<span class="plain">(- TEXT_TY_GetBlob({-new:text}, {-by-reference:T}, {N}, WORD_BLOB) -).</span>
|
|
<span class="plain">To decide what text is punctuated word number (N - a number) in (T - text)</span>
|
|
<span class="plain">(documented at ph_pwordnum):</span>
|
|
<span class="plain">(- TEXT_TY_GetBlob({-new:text}, {-by-reference:T}, {N}, PWORD_BLOB) -).</span>
|
|
<span class="plain">To decide what text is unpunctuated word number (N - a number) in (T - text)</span>
|
|
<span class="plain">(documented at ph_upwordnum):</span>
|
|
<span class="plain">(- TEXT_TY_GetBlob({-new:text}, {-by-reference:T}, {N}, UWORD_BLOB) -).</span>
|
|
<span class="plain">To decide what text is line number (N - a number) in (T - text)</span>
|
|
<span class="plain">(documented at ph_linenum):</span>
|
|
<span class="plain">(- TEXT_TY_GetBlob({-new:text}, {-by-reference:T}, {N}, LINE_BLOB) -).</span>
|
|
<span class="plain">To decide what text is paragraph number (N - a number) in (T - text)</span>
|
|
<span class="plain">(documented at ph_paranum):</span>
|
|
<span class="plain">(- TEXT_TY_GetBlob({-new:text}, {-by-reference:T}, {N}, PARA_BLOB) -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP33"></a><b>§33. </b>The "substituted form of" is a technicality most Inform users never need to
|
|
think about; as a one-off phrase, it may as well go here.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">To decide what text is the substituted form of (T - text)</span>
|
|
<span class="plain">(documented at ph_subform):</span>
|
|
<span class="plain">(- TEXT_TY_SubstitutedForm({-new:text}, {-by-reference:T}) -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP34"></a><b>§34. </b>A common matching engine is used for matching plain text...
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-TextReplacement</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 2 - Matching and Replacing</span>
|
|
|
|
<span class="plain">To decide if (T - text) exactly matches the text (find - text),</span>
|
|
<span class="plain">case insensitively</span>
|
|
<span class="plain">(documented at ph_exactlymatches):</span>
|
|
<span class="plain">(- TEXT_TY_Replace_RE(CHR_BLOB,{-by-reference:T},{-by-reference:find},0,{phrase options},1) -).</span>
|
|
<span class="plain">To decide if (T - text) matches the text (find - text),</span>
|
|
<span class="plain">case insensitively</span>
|
|
<span class="plain">(documented at ph_matches):</span>
|
|
<span class="plain">(- TEXT_TY_Replace_RE(CHR_BLOB,{-by-reference:T},{-by-reference:find},0,{phrase options}) -).</span>
|
|
<span class="plain">To decide what number is number of times (T - text) matches the text</span>
|
|
<span class="plain">(find - text), case insensitively</span>
|
|
<span class="plain">(documented at ph_nummatches):</span>
|
|
<span class="plain">(- TEXT_TY_Replace_RE(CHR_BLOB,{-by-reference:T},{-by-reference:find},1,{phrase options}) -).</span>
|
|
|
|
<span class="plain">To replace the text (find - text) in (T - text) with (replace - text),</span>
|
|
<span class="plain">case insensitively</span>
|
|
<span class="plain">(documented at ph_replace):</span>
|
|
<span class="plain">(- TEXT_TY_Replace_RE(CHR_BLOB, {-lvalue-by-reference:T}, {-by-reference:find},</span>
|
|
<span class="plain">{-by-reference:replace}, {phrase options}); -).</span>
|
|
<span class="plain">To replace the word (find - text) in (T - text) with</span>
|
|
<span class="plain">(replace - text)</span>
|
|
<span class="plain">(documented at ph_replacewordin):</span>
|
|
<span class="plain">(- TEXT_TY_ReplaceText(WORD_BLOB, {-lvalue-by-reference:T}, {-by-reference:find}, {-by-reference:replace}); -).</span>
|
|
<span class="plain">To replace the punctuated word (find - text) in (T - text)</span>
|
|
<span class="plain">with (replace - text)</span>
|
|
<span class="plain">(documented at ph_replacepwordin):</span>
|
|
<span class="plain">(- TEXT_TY_ReplaceText(PWORD_BLOB, {-lvalue-by-reference:T}, {-by-reference:find}, {-by-reference:replace}); -).</span>
|
|
|
|
<span class="plain">To replace character number (N - a number) in (T - text)</span>
|
|
<span class="plain">with (replace - text)</span>
|
|
<span class="plain">(documented at ph_replacechar):</span>
|
|
<span class="plain">(- TEXT_TY_ReplaceBlob(CHR_BLOB, {-lvalue-by-reference:T}, {N}, {-by-reference:replace}); -).</span>
|
|
<span class="plain">To replace word number (N - a number) in (T - text)</span>
|
|
<span class="plain">with (replace - text)</span>
|
|
<span class="plain">(documented at ph_replaceword):</span>
|
|
<span class="plain">(- TEXT_TY_ReplaceBlob(WORD_BLOB, {-lvalue-by-reference:T}, {N}, {-by-reference:replace}); -).</span>
|
|
<span class="plain">To replace punctuated word number (N - a number) in (T - text)</span>
|
|
<span class="plain">with (replace - text)</span>
|
|
<span class="plain">(documented at ph_replacepword):</span>
|
|
<span class="plain">(- TEXT_TY_ReplaceBlob(PWORD_BLOB, {-lvalue-by-reference:T}, {N}, {-by-reference:replace}); -).</span>
|
|
<span class="plain">To replace unpunctuated word number (N - a number) in (T - text)</span>
|
|
<span class="plain">with (replace - text)</span>
|
|
<span class="plain">(documented at ph_replaceupword):</span>
|
|
<span class="plain">(- TEXT_TY_ReplaceBlob(UWORD_BLOB, {-lvalue-by-reference:T}, {N}, {-by-reference:replace}); -).</span>
|
|
<span class="plain">To replace line number (N - a number) in (T - text) with (replace - text)</span>
|
|
<span class="plain">(documented at ph_replaceline):</span>
|
|
<span class="plain">(- TEXT_TY_ReplaceBlob(LINE_BLOB, {-lvalue-by-reference:T}, {N}, {-by-reference:replace}); -).</span>
|
|
<span class="plain">To replace paragraph number (N - a number) in (T - text) with (replace - text)</span>
|
|
<span class="plain">(documented at ph_replacepara):</span>
|
|
<span class="plain">(- TEXT_TY_ReplaceBlob(PARA_BLOB, {-lvalue-by-reference:T}, {N}, {-by-reference:replace}); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP35"></a><b>§35. </b>...and for regular expressions, though here we also have access to the
|
|
exact text which matched (not interesting in the plain text case since it's
|
|
the same as the search text, up to case at least), and the values of matched
|
|
subexpressions (which the plain text case doesn't have).
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-RegExp</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 3 - Regular Expressions</span>
|
|
|
|
<span class="plain">To decide if (T - text) exactly matches the regular expression (find - text),</span>
|
|
<span class="plain">case insensitively</span>
|
|
<span class="plain">(documented at ph_exactlymatchesre):</span>
|
|
<span class="plain">(- TEXT_TY_Replace_RE(REGEXP_BLOB,{-by-reference:T},{-by-reference:find},0,{phrase options},1) -).</span>
|
|
<span class="plain">To decide if (T - text) matches the regular expression (find - text),</span>
|
|
<span class="plain">case insensitively</span>
|
|
<span class="plain">(documented at ph_matchesre):</span>
|
|
<span class="plain">(- TEXT_TY_Replace_RE(REGEXP_BLOB,{-by-reference:T},{-by-reference:find},0,{phrase options}) -).</span>
|
|
<span class="plain">To decide what text is text matching regular expression</span>
|
|
<span class="plain">(documented at ph_matchtext):</span>
|
|
<span class="plain">(- TEXT_TY_RE_GetMatchVar(0) -).</span>
|
|
<span class="plain">To decide what text is text matching subexpression (N - a number)</span>
|
|
<span class="plain">(documented at ph_subexpressiontext):</span>
|
|
<span class="plain">(- TEXT_TY_RE_GetMatchVar({N}) -).</span>
|
|
<span class="plain">To decide what number is number of times (T - text) matches the regular expression</span>
|
|
<span class="plain">(find - text),case insensitively</span>
|
|
<span class="plain">(documented at ph_nummatchesre):</span>
|
|
<span class="plain">(- TEXT_TY_Replace_RE(REGEXP_BLOB,{-by-reference:T},{-by-reference:find},1,{phrase options}) -).</span>
|
|
<span class="plain">To replace the regular expression (find - text) in (T - text) with</span>
|
|
<span class="plain">(replace - text), case insensitively</span>
|
|
<span class="plain">(documented at ph_replacere):</span>
|
|
<span class="plain">(- TEXT_TY_Replace_RE(REGEXP_BLOB, {-lvalue-by-reference:T}, {-by-reference:find},</span>
|
|
<span class="plain">{-by-reference:replace}, {phrase options}); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP36"></a><b>§36. </b>Casing of text.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-TextCasing</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 4 - Casing of Text</span>
|
|
|
|
<span class="plain">To decide what text is (T - text) in lower case</span>
|
|
<span class="plain">(documented at ph_lowercase):</span>
|
|
<span class="plain">(- TEXT_TY_CharactersToCase({-new:text}, {-by-reference:T}, 0) -).</span>
|
|
<span class="plain">To decide what text is (T - text) in upper case</span>
|
|
<span class="plain">(documented at ph_uppercase):</span>
|
|
<span class="plain">(- TEXT_TY_CharactersToCase({-new:text}, {-by-reference:T}, 1) -).</span>
|
|
<span class="plain">To decide what text is (T - text) in title case</span>
|
|
<span class="plain">(documented at ph_titlecase):</span>
|
|
<span class="plain">(- TEXT_TY_CharactersToCase({-new:text}, {-by-reference:T}, 2) -).</span>
|
|
<span class="plain">To decide what text is (T - text) in sentence case</span>
|
|
<span class="plain">(documented at ph_sentencecase):</span>
|
|
<span class="plain">(- TEXT_TY_CharactersToCase({-new:text}, {-by-reference:T}, 3) -).</span>
|
|
<span class="plain">To decide if (T - text) is in lower case</span>
|
|
<span class="plain">(documented at ph_inlower):</span>
|
|
<span class="plain">(- TEXT_TY_CharactersOfCase({-by-reference:T}, 0) -).</span>
|
|
<span class="plain">To decide if (T - text) is in upper case</span>
|
|
<span class="plain">(documented at ph_inupper):</span>
|
|
<span class="plain">(- TEXT_TY_CharactersOfCase({-by-reference:T}, 1) -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP37"></a><b>§37. Adaptive text. </b></p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-AdaptiveText</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 5 - Adaptive Text</span>
|
|
|
|
<span class="plain">To say infinitive of (V - a verb)</span>
|
|
<span class="plain">(documented at phs_infinitive):</span>
|
|
<span class="plain">(- {V}(1); -).</span>
|
|
<span class="plain">To say past participle of (V - a verb)</span>
|
|
<span class="plain">(documented at phs_pastpart):</span>
|
|
<span class="plain">(- {V}(2); -).</span>
|
|
<span class="plain">To say present participle of (V - a verb)</span>
|
|
<span class="plain">(documented at phs_prespart):</span>
|
|
<span class="plain">(- {V}(3); -).</span>
|
|
|
|
<span class="plain">To say adapt (V - verb)</span>
|
|
<span class="plain">(documented at phs_adapt):</span>
|
|
<span class="plain">(- {V}(CV_POS, PNToVP(), story_tense); -).</span>
|
|
<span class="plain">To say adapt (V - verb) in (T - grammatical tense)</span>
|
|
<span class="plain">(documented at phs_adaptt):</span>
|
|
<span class="plain">(- {V}(CV_POS, PNToVP(), {T}); -).</span>
|
|
<span class="plain">To say adapt (V - verb) from (P - narrative viewpoint)</span>
|
|
<span class="plain">(documented at phs_adaptv):</span>
|
|
<span class="plain">(- {V}(CV_POS, {P}, story_tense); -).</span>
|
|
<span class="plain">To say adapt (V - verb) in (T - grammatical tense) from (P - narrative viewpoint)</span>
|
|
<span class="plain">(documented at phs_adaptvt):</span>
|
|
<span class="plain">(- {V}(CV_POS, {P}, {T}); -).</span>
|
|
<span class="plain">To say negate (V - verb)</span>
|
|
<span class="plain">(documented at phs_negate):</span>
|
|
<span class="plain">(- {V}(CV_NEG, PNToVP(), story_tense); -).</span>
|
|
<span class="plain">To say negate (V - verb) in (T - grammatical tense)</span>
|
|
<span class="plain">(documented at phs_negatet):</span>
|
|
<span class="plain">(- {V}(CV_NEG, PNToVP(), {T}); -).</span>
|
|
<span class="plain">To say negate (V - verb) from (P - narrative viewpoint)</span>
|
|
<span class="plain">(documented at phs_negatev):</span>
|
|
<span class="plain">(- {V}(CV_NEG, {P}, story_tense); -).</span>
|
|
<span class="plain">To say negate (V - verb) in (T - grammatical tense) from (P - narrative viewpoint)</span>
|
|
<span class="plain">(documented at phs_negatevt):</span>
|
|
<span class="plain">(- {V}(CV_NEG, {P}, {T}); -).</span>
|
|
|
|
<span class="plain">To decide which relation of objects is meaning of (V - a verb): (- {V}(CV_MEANING) -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP38"></a><b>§38. Data Structures. </b>Inform provides three main data structures: tables, lists, and relations,
|
|
which we will take in that order.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">Tables mimic tables of data as seen in books or scientific papers. Note that
|
|
changing a table entry is not something defined here as a phrase: the
|
|
ever-powerful "now" can do that. But changing something to a non-value —
|
|
or "blanking" it — requires specialist phrases.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Tables</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Chapter 6 - Data Structures</span>
|
|
|
|
<span class="plain">Section 1 - Tables</span>
|
|
|
|
<span class="plain">To choose a/the/-- row (N - number) in/from (T - table name)</span>
|
|
<span class="plain">(documented at ph_chooserow):</span>
|
|
<span class="plain">(- {-my:ct_0} = {T}; {-my:ct_1} = {N}; -).</span>
|
|
<span class="plain">To choose a/the/-- row with (TC - K valued table column) of (w - value of kind K)</span>
|
|
<span class="plain">in/from (T - table name)</span>
|
|
<span class="plain">(documented at ph_chooserowwith):</span>
|
|
<span class="plain">(- {-my:ct_0} = {T}; {-my:ct_1} = TableRowCorr(ct_0, {TC}, {w}); -).</span>
|
|
<span class="plain">To choose a/the/-- blank row in/from (T - table name)</span>
|
|
<span class="plain">(documented at ph_chooseblankrow):</span>
|
|
<span class="plain">(- {-my:ct_0} = {T}; {-my:ct_1} = TableBlankRow(ct_0); -).</span>
|
|
<span class="plain">To choose a/the/-- random row in/from (T - table name)</span>
|
|
<span class="plain">(documented at ph_chooserandomrow):</span>
|
|
<span class="plain">(- {-my:ct_0} = {T}; {-my:ct_1} = TableRandomRow(ct_0); -).</span>
|
|
<span class="plain">To decide which number is number of rows in/from (T - table name)</span>
|
|
<span class="plain">(documented at ph_numrows):</span>
|
|
<span class="plain">(- TableRows({T}) -).</span>
|
|
<span class="plain">To decide which number is number of blank rows in/from (T - table name)</span>
|
|
<span class="plain">(documented at ph_numblank):</span>
|
|
<span class="plain">(- TableBlankRows({T}) -).</span>
|
|
<span class="plain">To decide which number is number of filled rows in/from (T - table name)</span>
|
|
<span class="plain">(documented at ph_numfilled):</span>
|
|
<span class="plain">(- TableFilledRows({T}) -).</span>
|
|
<span class="plain">To decide if there is (TR - table-reference)</span>
|
|
<span class="plain">(documented at ph_thereis):</span>
|
|
<span class="plain">(- ({-reference-exists:TR}) -).</span>
|
|
<span class="plain">To decide if there is no (TR - table-reference)</span>
|
|
<span class="plain">(documented at ph_thereisno):</span>
|
|
<span class="plain">(- ({-reference-exists:TR} == false) -).</span>
|
|
<span class="plain">To blank out (tr - table-reference)</span>
|
|
<span class="plain">(documented at ph_blankout):</span>
|
|
<span class="plain">(- {-by-reference-blank-out:tr}; -).</span>
|
|
<span class="plain">To blank out the whole row</span>
|
|
<span class="plain">(documented at ph_blankoutrow):</span>
|
|
<span class="plain">(- TableBlankOutRow({-my:ct_0}, {-my:ct_1}); -).</span>
|
|
<span class="plain">To blank out the whole (TC - table column) in/from/of (T - table name)</span>
|
|
<span class="plain">(documented at ph_blankoutcol):</span>
|
|
<span class="plain">(- TableBlankOutColumn({T}, {TC}); -).</span>
|
|
<span class="plain">To blank out the whole of (T - table name)</span>
|
|
<span class="plain">(documented at ph_blankouttable):</span>
|
|
<span class="plain">(- TableBlankOutAll({T}); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP39"></a><b>§39. </b>These four are for debugging purposes only, and are used in the same test
|
|
case. "Showme the contents of ..." is not a text substitution, for efficiency
|
|
reasons: for a large table it could produce a gargantuan output, and in a
|
|
story file with memory constraints, one might not want to store that in a
|
|
text variable.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">To showme the contents of (T - table name)</span>
|
|
<span class="plain">(documented at ph_showmetable):</span>
|
|
<span class="plain">(- TableDebug({T}); -).</span>
|
|
<span class="plain">To say the/-- current table row</span>
|
|
<span class="plain">(documented at phs_currenttablerow):</span>
|
|
<span class="plain">(- TableRowDebug({-my:ct_0}, {-my:ct_1}); -).</span>
|
|
<span class="plain">To say row (N - number) in/from (T - table name)</span>
|
|
<span class="plain">(documented at phs_tablerow):</span>
|
|
<span class="plain">(- TableRowDebug({T}, {N}); -).</span>
|
|
<span class="plain">To say (TC - table column) in/from (T - table name)</span>
|
|
<span class="plain">(documented at phs_tablecolumn):</span>
|
|
<span class="plain">(- TableColumnDebug({T}, {TC}); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP40"></a><b>§40. </b>Sorting.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-TableSort</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 2 - Sorting Tables</span>
|
|
|
|
<span class="plain">To sort (T - table name) in/into random order</span>
|
|
<span class="plain">(documented at ph_sortrandom):</span>
|
|
<span class="plain">(- TableShuffle({T}); -).</span>
|
|
<span class="plain">To sort (T - table name) in/into (TC - table column) order</span>
|
|
<span class="plain">(documented at ph_sortcolumn):</span>
|
|
<span class="plain">(- TableSort({T}, {TC}, 1); -).</span>
|
|
<span class="plain">To sort (T - table name) in/into reverse (TC - table column) order</span>
|
|
<span class="plain">(documented at ph_sortcolumnreverse):</span>
|
|
<span class="plain">(- TableSort({T}, {TC}, -1); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP41"></a><b>§41. Lists. </b>The following are all for adding and removing values to dynamic lists.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Lists</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 3 - Lists</span>
|
|
|
|
<span class="plain">To add (new entry - K) to (L - list of values of kind K), if absent</span>
|
|
<span class="plain">(documented at ph_addtolist):</span>
|
|
<span class="plain">(- LIST_OF_TY_InsertItem({-lvalue-by-reference:L}, {new entry}, 0, 0, {phrase options}); -).</span>
|
|
|
|
<span class="plain">To add (new entry - K) at entry (E - number) in (L - list of values of kind K), if absent</span>
|
|
<span class="plain">(documented at ph_addatentry):</span>
|
|
<span class="plain">(- LIST_OF_TY_InsertItem({-lvalue-by-reference:L}, {new entry}, 1, {E}, {phrase options}); -).</span>
|
|
|
|
<span class="plain">To add (LX - list of Ks) to (L - list of values of kind K), if absent</span>
|
|
<span class="plain">(documented at ph_addlisttolist):</span>
|
|
<span class="plain">(- LIST_OF_TY_AppendList({-lvalue-by-reference:L}, {-by-reference:LX}, 0, 0, {phrase options}); -).</span>
|
|
|
|
<span class="plain">To add (LX - list of Ks) at entry (E - number) in (L - list of values of kind K)</span>
|
|
<span class="plain">(documented at ph_addlistatentry):</span>
|
|
<span class="plain">(- LIST_OF_TY_AppendList({-lvalue-by-reference:L}, {-by-reference:LX}, 1, {E}, 0); -).</span>
|
|
|
|
<span class="plain">To remove (existing entry - K) from (L - list of values of kind K), if present</span>
|
|
<span class="plain">(documented at ph_remfromlist):</span>
|
|
<span class="plain">(- LIST_OF_TY_RemoveValue({-lvalue-by-reference:L}, {existing entry}, {phrase options}); -).</span>
|
|
|
|
<span class="plain">To remove (N - list of Ks) from (L - list of values of kind K), if present</span>
|
|
<span class="plain">(documented at ph_remlistfromlist):</span>
|
|
<span class="plain">(- LIST_OF_TY_Remove_List({-lvalue-by-reference:L}, {-by-reference:N}, {phrase options}); -).</span>
|
|
|
|
<span class="plain">To remove entry (N - number) from (L - list of values), if present</span>
|
|
<span class="plain">(documented at ph_rementry):</span>
|
|
<span class="plain">(- LIST_OF_TY_RemoveItemRange({-lvalue-by-reference:L}, {N}, {N}, {phrase options}); -).</span>
|
|
|
|
<span class="plain">To remove entries (N - number) to (N2 - number) from (L - list of values), if present</span>
|
|
<span class="plain">(documented at ph_rementries):</span>
|
|
<span class="plain">(- LIST_OF_TY_RemoveItemRange({-lvalue-by-reference:L}, {N}, {N2}, {phrase options}); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP42"></a><b>§42. </b>Searching a list is implemented in a somewhat crude way at present, and the
|
|
following syntax may later be replaced with a suitable verb "to be listed
|
|
in", so that there's no need to imitate.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">To decide if (N - K) is listed in (L - list of values of kind K)</span>
|
|
<span class="plain">(documented at ph_islistedin):</span>
|
|
<span class="plain">(- (LIST_OF_TY_FindItem({-by-reference:L}, {N})) -).</span>
|
|
|
|
<span class="plain">To decide if (N - K) is not listed in (L - list of values of kind K)</span>
|
|
<span class="plain">(documented at ph_isnotlistedin):</span>
|
|
<span class="plain">(- (LIST_OF_TY_FindItem({-by-reference:L}, {N}) == false) -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP43"></a><b>§43. </b>A description is a representation of a set of objects by means of a
|
|
predicate (e.g., "open unlocked doors"), and it converts into a list of
|
|
current members (in creation order), but there's no reverse process.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">To decide what list of Ks is the list of (D - description of values of kind K)</span>
|
|
<span class="plain">(documented at ph_listofdesc):</span>
|
|
<span class="plain">(- {-new-list-of:list of K} -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP44"></a><b>§44. </b>Determining and setting the length:
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-ListLength</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 4 - Length of lists</span>
|
|
|
|
<span class="plain">To decide what number is the number of entries in/of (L - a list of values)</span>
|
|
<span class="plain">(documented at ph_numberentries):</span>
|
|
<span class="plain">(- LIST_OF_TY_GetLength({-by-reference:L}) -).</span>
|
|
<span class="plain">To truncate (L - a list of values) to (N - a number) entries/entry</span>
|
|
<span class="plain">(documented at ph_truncate):</span>
|
|
<span class="plain">(- LIST_OF_TY_SetLength({-lvalue-by-reference:L}, {N}, -1, 1); -).</span>
|
|
<span class="plain">To truncate (L - a list of values) to the first (N - a number) entries/entry</span>
|
|
<span class="plain">(documented at ph_truncatefirst):</span>
|
|
<span class="plain">(- LIST_OF_TY_SetLength({-lvalue-by-reference:L}, {N}, -1, 1); -).</span>
|
|
<span class="plain">To truncate (L - a list of values) to the last (N - a number) entries/entry</span>
|
|
<span class="plain">(documented at ph_truncatelast):</span>
|
|
<span class="plain">(- LIST_OF_TY_SetLength({-lvalue-by-reference:L}, {N}, -1, -1); -).</span>
|
|
<span class="plain">To extend (L - a list of values) to (N - a number) entries/entry</span>
|
|
<span class="plain">(documented at ph_extend):</span>
|
|
<span class="plain">(- LIST_OF_TY_SetLength({-lvalue-by-reference:L}, {N}, 1); -).</span>
|
|
<span class="plain">To change (L - a list of values) to have (N - a number) entries/entry</span>
|
|
<span class="plain">(documented at ph_changelength):</span>
|
|
<span class="plain">(- LIST_OF_TY_SetLength({-lvalue-by-reference:L}, {N}, 0); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP45"></a><b>§45. </b>Easy but useful list operations. Sorting ultimately uses a common sorting
|
|
mechanism, in "Sort.i6t", which handles both lists and tables.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-ListOperations</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 5 - List operations</span>
|
|
|
|
<span class="plain">To reverse (L - a list of values)</span>
|
|
<span class="plain">(documented at ph_reverselist):</span>
|
|
<span class="plain">(- LIST_OF_TY_Reverse({-lvalue-by-reference:L}); -).</span>
|
|
<span class="plain">To rotate (L - a list of values)</span>
|
|
<span class="plain">(documented at ph_rotatelist):</span>
|
|
<span class="plain">(- LIST_OF_TY_Rotate({-lvalue-by-reference:L}, 0); -).</span>
|
|
<span class="plain">To rotate (L - a list of values) backwards</span>
|
|
<span class="plain">(documented at ph_rotatelistback):</span>
|
|
<span class="plain">(- LIST_OF_TY_Rotate({-lvalue-by-reference:L}, 1); -).</span>
|
|
<span class="plain">To sort (L - a list of values)</span>
|
|
<span class="plain">(documented at ph_sortlist):</span>
|
|
<span class="plain">(- LIST_OF_TY_Sort({-lvalue-by-reference:L}, 1); -).</span>
|
|
<span class="plain">To sort (L - a list of values) in/into reverse order</span>
|
|
<span class="plain">(documented at ph_sortlistreverse):</span>
|
|
<span class="plain">(- LIST_OF_TY_Sort({-lvalue-by-reference:L}, -1); -).</span>
|
|
<span class="plain">To sort (L - a list of values) in/into random order</span>
|
|
<span class="plain">(documented at ph_sortlistrandom):</span>
|
|
<span class="plain">(- LIST_OF_TY_Sort({-lvalue-by-reference:L}, 2); -).</span>
|
|
<span class="plain">To sort (L - a list of objects) in/into (P - property) order</span>
|
|
<span class="plain">(documented at ph_sortlistproperty):</span>
|
|
<span class="plain">(- LIST_OF_TY_Sort({-lvalue-by-reference:L}, 1, {P}, {-property-holds-block-value:P}); -).</span>
|
|
<span class="plain">To sort (L - a list of objects) in/into reverse (P - property) order</span>
|
|
<span class="plain">(documented at ph_sortlistpropertyreverse):</span>
|
|
<span class="plain">(- LIST_OF_TY_Sort({-lvalue-by-reference:L}, -1, {P}, {-property-holds-block-value:P}); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP46"></a><b>§46. </b>Relations are the final data structure given here. In some ways they are
|
|
the most fundamental of all, but they're not either set or tested by
|
|
procedural phrases — they lie in the linguistic structure of conditions.
|
|
So all we have here are the route-finding phrases:
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Relations</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 6 - Relations</span>
|
|
|
|
<span class="plain">To show relation (R - relation)</span>
|
|
<span class="plain">(documented at ph_showrelation):</span>
|
|
<span class="plain">(- {-show-me:R}; RelationTest({-by-reference:R}, RELS_SHOW); -).</span>
|
|
|
|
<span class="plain">To decide which object is next step via (R - relation of objects)</span>
|
|
<span class="plain">from (O1 - object) to (O2 - object)</span>
|
|
<span class="plain">(documented at ph_nextstep):</span>
|
|
<span class="plain">(- RelationRouteTo({-by-reference:R},{O1},{O2},false) -).</span>
|
|
<span class="plain">To decide which number is number of steps via (R - relation of objects)</span>
|
|
<span class="plain">from (O1 - object) to (O2 - object)</span>
|
|
<span class="plain">(documented at ph_numbersteps):</span>
|
|
<span class="plain">(- RelationRouteTo({-by-reference:R},{O1},{O2},true) -).</span>
|
|
|
|
<span class="plain">To decide which list of Ks is list of (name of kind of value K)</span>
|
|
<span class="plain">that/which/whom (R - relation of Ks to values of kind L) relates</span>
|
|
<span class="plain">(documented at ph_leftdomain):</span>
|
|
<span class="plain">(- RelationTest({-by-reference:R}, RELS_LIST, {-new:list of K}, RLIST_ALL_X) -).</span>
|
|
|
|
<span class="plain">To decide which list of Ls is list of (name of kind of value L)</span>
|
|
<span class="plain">to which/whom (R - relation of values of kind K to Ls) relates</span>
|
|
<span class="plain">(documented at ph_rightdomain):</span>
|
|
<span class="plain">(- RelationTest({-by-reference:R}, RELS_LIST, {-new:list of L}, RLIST_ALL_Y) -). [1]</span>
|
|
|
|
<span class="plain">To decide which list of Ls is list of (name of kind of value L)</span>
|
|
<span class="plain">that/which/whom (R - relation of values of kind K to Ls) relates to</span>
|
|
<span class="plain">(documented at ph_rightdomain):</span>
|
|
<span class="plain">(- RelationTest({-by-reference:R}, RELS_LIST, {-new:list of L}, RLIST_ALL_Y) -). [2]</span>
|
|
|
|
<span class="plain">To decide which list of Ks is list of (name of kind of value K) that/which/who</span>
|
|
<span class="plain">relate to (Y - L) by (R - relation of Ks to values of kind L)</span>
|
|
<span class="plain">(documented at ph_leftlookuplist):</span>
|
|
<span class="plain">(- RelationTest({-by-reference:R}, RELS_LOOKUP_ALL_X, {Y}, {-new:list of K}) -).</span>
|
|
|
|
<span class="plain">To decide which list of Ls is list of (name of kind of value L) to which/whom (X - K)</span>
|
|
<span class="plain">relates by (R - relation of values of kind K to Ls)</span>
|
|
<span class="plain">(documented at ph_rightlookuplist):</span>
|
|
<span class="plain">(- RelationTest({-by-reference:R}, RELS_LOOKUP_ALL_Y, {X}, {-new:list of L}) -). [1]</span>
|
|
|
|
<span class="plain">To decide which list of Ls is list of (name of kind of value L)</span>
|
|
<span class="plain">that/which/whom (X - K) relates to by (R - relation of values of kind K to Ls)</span>
|
|
<span class="plain">(documented at ph_rightlookuplist):</span>
|
|
<span class="plain">(- RelationTest({-by-reference:R}, RELS_LOOKUP_ALL_Y, {X}, {-new:list of L}) -). [2]</span>
|
|
|
|
<span class="plain">To decide whether (name of kind of value K) relates to (Y - L) by</span>
|
|
<span class="plain">(R - relation of Ks to values of kind L)</span>
|
|
<span class="plain">(documented at ph_ifright):</span>
|
|
<span class="plain">(- RelationTest({-by-reference:R}, RELS_LOOKUP_ANY, {Y}, RLANY_CAN_GET_X) -).</span>
|
|
|
|
<span class="plain">To decide whether (X - K) relates to (name of kind of value L) by</span>
|
|
<span class="plain">(R - relation of values of kind K to Ls)</span>
|
|
<span class="plain">(documented at ph_ifleft):</span>
|
|
<span class="plain">(- RelationTest({-by-reference:R}, RELS_LOOKUP_ANY, {X}, RLANY_CAN_GET_Y) -).</span>
|
|
|
|
<span class="plain">To decide which K is (name of kind of value K) that/which/who relates to</span>
|
|
<span class="plain">(Y - L) by (R - relation of Ks to values of kind L)</span>
|
|
<span class="plain">(documented at ph_leftlookup):</span>
|
|
<span class="plain">(- RelationTest({-by-reference:R}, RELS_LOOKUP_ANY, {Y}, RLANY_GET_X) -).</span>
|
|
|
|
<span class="plain">To decide which L is (name of kind of value L) to which/whom (X - K)</span>
|
|
<span class="plain">relates by (R - relation of values of kind K to Ls)</span>
|
|
<span class="plain">(documented at ph_rightlookup):</span>
|
|
<span class="plain">(- RelationTest({-by-reference:R}, RELS_LOOKUP_ANY, {X}, RLANY_GET_Y) -). [1]</span>
|
|
|
|
<span class="plain">To decide which L is (name of kind of value L) that/which/whom (X - K)</span>
|
|
<span class="plain">relates to by (R - relation of values of kind K to Ls)</span>
|
|
<span class="plain">(documented at ph_rightlookup):</span>
|
|
<span class="plain">(- RelationTest({-by-reference:R}, RELS_LOOKUP_ANY, {X}, RLANY_GET_Y) -). [2]</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP47"></a><b>§47. Functional Programming. </b>Here we have the ability to use the name of a function as a value, and to
|
|
apply such a function.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Apply</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Chapter 7 - Functional Programming</span>
|
|
|
|
<span class="plain">Section 1 - Applying Functions</span>
|
|
|
|
<span class="plain">To decide whether (val - K) matches (desc - description of values of kind K)</span>
|
|
<span class="plain">(documented at ph_valuematch):</span>
|
|
<span class="plain">(- {-primitive-definition:description-application} -).</span>
|
|
|
|
<span class="plain">To decide what K is (function - phrase nothing -> value of kind K) applied</span>
|
|
<span class="plain">(documented at ph_applied0):</span>
|
|
<span class="plain">(- {-primitive-definition:function-application} -).</span>
|
|
|
|
<span class="plain">To decide what L is (function - phrase value of kind K -> value of kind L)</span>
|
|
<span class="plain">applied to (input - K)</span>
|
|
<span class="plain">(documented at ph_applied1):</span>
|
|
<span class="plain">(- {-primitive-definition:function-application} -).</span>
|
|
|
|
<span class="plain">To decide what M is (function - phrase (value of kind K, value of kind L) -> value of kind M)</span>
|
|
<span class="plain">applied to (input - K) and (second input - L)</span>
|
|
<span class="plain">(documented at ph_applied2):</span>
|
|
<span class="plain">(- {-primitive-definition:function-application} -).</span>
|
|
|
|
<span class="plain">To decide what N is (function - phrase (value of kind K, value of kind L, value of kind M) -> value of kind N)</span>
|
|
<span class="plain">applied to (input - K) and (second input - L) and (third input - M)</span>
|
|
<span class="plain">(documented at ph_applied3):</span>
|
|
<span class="plain">(- {-primitive-definition:function-application} -).</span>
|
|
|
|
<span class="plain">To apply (function - phrase nothing -> nothing)</span>
|
|
<span class="plain">(documented at ph_apply0):</span>
|
|
<span class="plain">(- {-primitive-definition:function-application}; -).</span>
|
|
|
|
<span class="plain">To apply (function - phrase value of kind K -> nothing)</span>
|
|
<span class="plain">to (input - K)</span>
|
|
<span class="plain">(documented at ph_apply1):</span>
|
|
<span class="plain">(- {-primitive-definition:function-application}; -).</span>
|
|
|
|
<span class="plain">To apply (function - phrase (value of kind K, value of kind L) -> nothing)</span>
|
|
<span class="plain">to (input - K) and (second input - L)</span>
|
|
<span class="plain">(documented at ph_apply2):</span>
|
|
<span class="plain">(- {-primitive-definition:function-application}; -).</span>
|
|
|
|
<span class="plain">To apply (function - phrase (value of kind K, value of kind L, value of kind M) -> nothing)</span>
|
|
<span class="plain">to (input - K) and (second input - L) and (third input - M)</span>
|
|
<span class="plain">(documented at ph_apply3):</span>
|
|
<span class="plain">(- {-primitive-definition:function-application}; -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP48"></a><b>§48. </b>The standard map, reduce and filter operations found in most functional
|
|
programming languages also have Inform analogues.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Map</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 2 - Working with Lists</span>
|
|
|
|
<span class="plain">To decide what list of L is (function - phrase K -> value of kind L) applied to (original list - list of values of kind K)</span>
|
|
<span class="plain">(documented at ph_appliedlist):</span>
|
|
<span class="plain">let the result be a list of Ls;</span>
|
|
<span class="plain">repeat with item running through the original list:</span>
|
|
<span class="plain">let the mapped item be the function applied to the item;</span>
|
|
<span class="plain">add the mapped item to the result;</span>
|
|
<span class="plain">decide on the result.</span>
|
|
|
|
<span class="plain">To decide what K is the (function - phrase (K, K) -> K) reduction of (original list - list of values of kind K)</span>
|
|
<span class="plain">(documented at ph_reduction):</span>
|
|
<span class="plain">let the total be a K;</span>
|
|
<span class="plain">let the count be 0;</span>
|
|
<span class="plain">repeat with item running through the original list:</span>
|
|
<span class="plain">increase the count by 1;</span>
|
|
<span class="plain">if the count is 1, now the total is the item;</span>
|
|
<span class="plain">otherwise now the total is the function applied to the total and the item;</span>
|
|
<span class="plain">decide on the total.</span>
|
|
|
|
<span class="plain">To decide what list of K is the filter to (criterion - description of Ks) of</span>
|
|
<span class="plain">(full list - list of values of kind K)</span>
|
|
<span class="plain">(documented at ph_filter):</span>
|
|
<span class="plain">let the filtered list be a list of K;</span>
|
|
<span class="plain">repeat with item running through the full list:</span>
|
|
<span class="plain">if the item matches the criterion:</span>
|
|
<span class="plain">add the item to the filtered list;</span>
|
|
<span class="plain">decide on the filtered list.</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP49"></a><b>§49. Rulebooks and Activities. </b></p>
|
|
|
|
<p class="inwebparagraph">Firing off activities:
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Activities</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Chapter 8 - Rulebooks and Activities</span>
|
|
|
|
<span class="plain">Section 1 - Carrying out Activities</span>
|
|
|
|
<span class="plain">To carry out the (A - activity on nothing) activity</span>
|
|
<span class="plain">(documented at ph_carryout):</span>
|
|
<span class="plain">(- CarryOutActivity({A}); -).</span>
|
|
<span class="plain">To carry out the (A - activity on value of kind K) activity with (val - K)</span>
|
|
<span class="plain">(documented at ph_carryoutwith):</span>
|
|
<span class="plain">(- CarryOutActivity({A}, {val}); -).</span>
|
|
<span class="plain">To continue the activity</span>
|
|
<span class="plain">(documented at ph_continueactivity):</span>
|
|
<span class="plain">(- rfalse; -) - in to only.</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP50"></a><b>§50. </b>Advanced activity phrases: for setting up one's own activities structured
|
|
around I7 source text. People tend not to use this much, and perhaps that's
|
|
a good thing, but it does open up possibilities, and it's good for
|
|
retro-fitting onto extensions to make them more customisable.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">These are really only useful in an activity-rich environment, in any case.
|
|
See the documentation example <code class="display"><span class="extract">AntSensitiveSunglasses</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 2 - Advanced Activities</span>
|
|
|
|
<span class="plain">To begin the (A - activity on nothing) activity</span>
|
|
<span class="plain">(documented at ph_beginactivity):</span>
|
|
<span class="plain">(- BeginActivity({A}); -).</span>
|
|
<span class="plain">To begin the (A - activity on value of kind K) activity with (val - K)</span>
|
|
<span class="plain">(documented at ph_beginactivitywith):</span>
|
|
<span class="plain">(- BeginActivity({A}, {val}); -).</span>
|
|
<span class="plain">To decide whether handling (A - activity) activity</span>
|
|
<span class="plain">(documented at ph_handlingactivity):</span>
|
|
<span class="plain">(- (~~(ForActivity({A}))) -).</span>
|
|
<span class="plain">To decide whether handling (A - activity on value of kind K) activity with (val - K)</span>
|
|
<span class="plain">(documented at ph_handlingactivitywith):</span>
|
|
<span class="plain">(- (~~(ForActivity({A}, {val}))) -).</span>
|
|
<span class="plain">To end the (A - activity on nothing) activity</span>
|
|
<span class="plain">(documented at ph_endactivity):</span>
|
|
<span class="plain">(- EndActivity({A}); -).</span>
|
|
<span class="plain">To end the (A - activity on value of kind K) activity with (val - K)</span>
|
|
<span class="plain">(documented at ph_endactivitywith):</span>
|
|
<span class="plain">(- EndActivity({A}, {val}); -).</span>
|
|
<span class="plain">To abandon the (A - activity on nothing) activity</span>
|
|
<span class="plain">(documented at ph_abandonactivity):</span>
|
|
<span class="plain">(- AbandonActivity({A}); -).</span>
|
|
<span class="plain">To abandon the (A - activity on value of kind K) activity with (val - K)</span>
|
|
<span class="plain">(documented at ph_abandonactivitywith):</span>
|
|
<span class="plain">(- AbandonActivity({A}, {val}); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP51"></a><b>§51. </b>Here are four different ways to invoke a rule or rulebook:
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Rules</span></code>.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 3 - Following Rules</span>
|
|
|
|
<span class="plain">To follow (RL - a rule)</span>
|
|
<span class="plain">(documented at ph_follow):</span>
|
|
<span class="plain">(- FollowRulebook({RL}); -).</span>
|
|
<span class="plain">To follow (RL - value of kind K based rule producing a value) for (V - K)</span>
|
|
<span class="plain">(documented at ph_followfor):</span>
|
|
<span class="plain">(- FollowRulebook({RL}, {V}, true); -).</span>
|
|
<span class="plain">To follow (RL - a nothing based rule)</span>
|
|
<span class="plain">(documented at ph_follow):</span>
|
|
<span class="plain">(- FollowRulebook({RL}); -).</span>
|
|
<span class="plain">To decide what K is the (name of kind K) produced by (RL - rule producing a value of kind K)</span>
|
|
<span class="plain">(documented at ph_producedby):</span>
|
|
<span class="plain">(- ResultOfRule({RL}, 0, true, {-strong-kind:K}) -).</span>
|
|
<span class="plain">To decide what L is the (name of kind L) produced by (RL - value of kind K based rule</span>
|
|
<span class="plain">producing a value of kind L) for (V - K)</span>
|
|
<span class="plain">(documented at ph_producedbyfor):</span>
|
|
<span class="plain">(- ResultOfRule({RL}, {V}, true, {-strong-kind:L}) -).</span>
|
|
<span class="plain">To decide what K is the (name of kind K) produced by (RL - nothing based rule producing a value of kind K)</span>
|
|
<span class="plain">(documented at ph_producedby):</span>
|
|
<span class="plain">(- ResultOfRule({RL}, 0, true, {-strong-kind:K}) -).</span>
|
|
<span class="plain">To abide by (RL - a rule)</span>
|
|
<span class="plain">(documented at ph_abide):</span>
|
|
<span class="plain">(- if (FollowRulebook({RL})) rtrue; -) - in to only.</span>
|
|
<span class="plain">To abide by (RL - value of kind K based rule producing a value) for (V - K)</span>
|
|
<span class="plain">(documented at ph_abidefor):</span>
|
|
<span class="plain">(- if (FollowRulebook({RL}, {V}, true)) rtrue; -) - in to only.</span>
|
|
<span class="plain">To abide by (RL - a nothing based rule)</span>
|
|
<span class="plain">(documented at ph_abide):</span>
|
|
<span class="plain">(- if (FollowRulebook({RL})) rtrue; -) - in to only.</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP52"></a><b>§52. </b>Rules return <code class="display"><span class="extract">true</span></code> to indicate a decision, which could be either a success
|
|
or a failure, and optionally may also return a value. If they return <code class="display"><span class="extract">false</span></code>,
|
|
there's no decision.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Rules</span></code> once again.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 4 - Success and Failure</span>
|
|
|
|
<span class="plain">To make no decision</span>
|
|
<span class="plain">(documented at ph_nodecision): (- rfalse; -) - in to only.</span>
|
|
<span class="plain">To rule succeeds</span>
|
|
<span class="plain">(documented at ph_succeeds):</span>
|
|
<span class="plain">(- RulebookSucceeds(); rtrue; -) - in to only.</span>
|
|
<span class="plain">To rule fails</span>
|
|
<span class="plain">(documented at ph_fails):</span>
|
|
<span class="plain">(- RulebookFails(); rtrue; -) - in to only.</span>
|
|
<span class="plain">To rule succeeds with result (val - a value)</span>
|
|
<span class="plain">(documented at ph_succeedswith):</span>
|
|
<span class="plain">(- RulebookSucceeds({-weak-kind:rule-return-kind},{-return-value-from-rule:val}); rtrue; -) - in to only.</span>
|
|
<span class="plain">To decide if rule succeeded</span>
|
|
<span class="plain">(documented at ph_succeeded):</span>
|
|
<span class="plain">(- (RulebookSucceeded()) -).</span>
|
|
<span class="plain">To decide if rule failed</span>
|
|
<span class="plain">(documented at ph_failed):</span>
|
|
<span class="plain">(- (RulebookFailed()) -).</span>
|
|
<span class="plain">To decide which rulebook outcome is the outcome of the rulebook</span>
|
|
<span class="plain">(documented at ph_rulebookoutcome):</span>
|
|
<span class="plain">(- (ResultOfRule()) -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP53"></a><b>§53. External Files. </b>Inform has a quirky level of support for file-handling, which comes out what
|
|
the Glulx virtual machine will support.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">See test case <code class="display"><span class="extract">BIP-Files-G</span></code>, which has no Z-machine counterpart.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Chapter 9 - External Files (not for Z-machine)</span>
|
|
|
|
<span class="plain">Section 1 - Files of Text</span>
|
|
|
|
<span class="plain">To write (T - text) to (FN - external file)</span>
|
|
<span class="plain">(documented at ph_writetext):</span>
|
|
<span class="plain">(- FileIO_PutContents({FN}, {T}, false); -).</span>
|
|
<span class="plain">To append (T - text) to (FN - external file)</span>
|
|
<span class="plain">(documented at ph_appendtext):</span>
|
|
<span class="plain">(- FileIO_PutContents({FN}, {T}, true); -).</span>
|
|
<span class="plain">To say text of (FN - external file)</span>
|
|
<span class="plain">(documented at ph_saytext):</span>
|
|
<span class="plain">(- FileIO_PrintContents({FN}); say__p = 1; -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP54"></a><b>§54. </b>See test case <code class="display"><span class="extract">BIP-FilesOfTables-G</span></code>, which has no Z-machine counterpart.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 2 - Files of Data</span>
|
|
|
|
<span class="plain">To read (filename - external file) into (T - table name)</span>
|
|
<span class="plain">(documented at ph_readtable):</span>
|
|
<span class="plain">(- FileIO_GetTable({filename}, {T}); -).</span>
|
|
<span class="plain">To write (filename - external file) from (T - table name)</span>
|
|
<span class="plain">(documented at ph_writetable):</span>
|
|
<span class="plain">(- FileIO_PutTable({filename}, {T}); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP55"></a><b>§55. </b>These are hardly used phrases which are difficult to test convincingly
|
|
in our framework, since they defend against independent Inform programs
|
|
simultaneously trying to access the same file.
|
|
</p>
|
|
|
|
|
|
<pre class="display">
|
|
<span class="plain">Section 3 - File Handling</span>
|
|
|
|
<span class="plain">To decide if (filename - external file) exists</span>
|
|
<span class="plain">(documented at ph_fileexists):</span>
|
|
<span class="plain">(- (FileIO_Exists({filename}, false)) -).</span>
|
|
<span class="plain">To decide if ready to read (filename - external file)</span>
|
|
<span class="plain">(documented at ph_fileready):</span>
|
|
<span class="plain">(- (FileIO_Ready({filename}, false)) -).</span>
|
|
<span class="plain">To mark (filename - external file) as ready to read</span>
|
|
<span class="plain">(documented at ph_markfileready):</span>
|
|
<span class="plain">(- FileIO_MarkReady({filename}, true); -).</span>
|
|
<span class="plain">To mark (filename - external file) as not ready to read</span>
|
|
<span class="plain">(documented at ph_markfilenotready):</span>
|
|
<span class="plain">(- FileIO_MarkReady({filename}, false); -).</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<hr class="tocbar">
|
|
<ul class="toc"><li><a href="S-md.html">Back to 'Miscellaneous Definitions'</a></li><li><a href="S-ad.html">Continue with 'Adjectival Definitions'</a></li></ul><hr class="tocbar">
|
|
<!--End of weave-->
|
|
</body>
|
|
</html>
|
|
|