Doc: Minor fix.
[shapes.git] / doc / parts / extensions / program-flow.sxml
blobc3813de855703d6dec56c33512d3ce6e8b6e1b47
1 <?xml version="1.0" encoding="UTF-8"?>
2 <?xml-stylesheet type="text/xsl" href="formats/html.xsl"?>
4 <!-- This file is part of Shapes. -->
5 <!-- -->
6 <!-- Shapes is free software: you can redistribute it and/or modify -->
7 <!-- it under the terms of the GNU General Public License as published by -->
8 <!-- the Free Software Foundation, either version 3 of the License, or -->
9 <!-- any later version. -->
10 <!-- -->
11 <!-- Shapes is distributed in the hope that it will be useful, -->
12 <!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
13 <!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
14 <!-- GNU General Public License for more details. -->
15 <!-- -->
16 <!-- You should have received a copy of the GNU General Public License -->
17 <!-- along with Shapes. If not, see <http://www.gnu.org/licenses/>. -->
18 <!-- -->
19 <!-- Copyright 2009 Henrik Tidefelt -->
22 <book>
23 <title>program-flow</title>
24 <description>
25 <p>Abstractions for program flow control.</p>
26 </description>
27 <meta-selflink><extension-href name="program-flow" /></meta-selflink>
28 <base href=<!--#expand-next-string-->"$(BASE)" />
29 <examples-home href=<!--#expand-next-string-->"$(EXAMPLES)" />
30 <up-link><a part="extensions">All extensions</a></up-link>
31 <prelude />
32 <needs></needs>
33 <top>
34 <alphabetical-index/>
35 <p>The primary tools that the <str-Shapes /> core language provides for program flow control and conditional evaluation, are the escape continuations and the <binding name="if" /> function. This extension provides abstractions for some other common conditional constructs found in other programming languages.</p>
36 </top>
38 <section id="extensions/program-flow/cond">
39 <title>Multi-clause conditionals</title>
40 <body>
41 <p>At the moment, there is just one function here.</p>
43 <system-binding identifier="cond">
44 <function>
45 <case>
46 <arguments>
47 <sink>
48 <type><named-type name="ConsPair" /></type>
49 </sink>
50 </arguments>
51 <result>
52 <type><named-type name="Value" /></type>
53 </result>
54 <dynamic-references></dynamic-references>
55 <description>
56 <p>Takes any number of <named-type name="ConsPair" /> pairs as arguments, and searches from left for a pair with true <field name="car" /> (predicate) part, returning the corresponding <field name="cdr" /> (consequence) part.</p>
57 <p>To provide a default result one must simply pass a <named-type name="ConsPair" /> with a predicate part which is just <inline>true</inline>.</p>
58 <example-with-output title="Using the cond function" internal-id="program-flow/cond-example">
59 <source file="features/error.shape">
60 <![CDATA[<!--#include depth="0" virtual="$(BUILDDIR)$(EXAMPLES)features/error.shape" -->]]>
61 </source>
62 <stdout>
63 <![CDATA[<!--#include depth="0" virtual="$(BUILDDIR)$(EXAMPLES)features/error.stdout" -->]]>
64 </stdout>
65 <caption>
66 <p>One application of <binding name="cond" />, and one case where <binding name="cond" /> could have been used, but wasn't.</p>
67 </caption>
68 </example-with-output>
69 </description>
70 </case>
71 </function>
72 </system-binding>
74 </body>
75 </section>
77 </book>