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. -->
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. -->
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. -->
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/>. -->
19 <!-- Copyright 2009 Henrik Tidefelt -->
23 <title>program-flow
</title>
25 <p>Abstractions for program flow control.
</p>
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>
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>
38 <section id=
"extensions/program-flow/cond">
39 <title>Multi-clause conditionals
</title>
41 <p>At the moment, there is just one function here.
</p>
43 <system-binding identifier=
"cond">
48 <type><named-type name=
"ConsPair" /></type>
52 <type><named-type name=
"Value" /></type>
54 <dynamic-references></dynamic-references>
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" -->]]
>
63 <![CDATA[
<!--#include depth="0" virtual="$(BUILDDIR)$(EXAMPLES)features/error.stdout" -->]]
>
66 <p>One application of
<binding name=
"cond" />, and one case where
<binding name=
"cond" /> could have been used, but wasn't.
</p>
68 </example-with-output>