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 2008, 2014 Henrik Tidefelt -->
23 <title>conssupport
</title>
25 <p>Tools for working with cons-style lists (à la Scheme, for instance).
</p>
27 <meta-selflink><self-href /></meta-selflink>
28 <base href=
<!--#expand-next-string-->"$(BASE)" />
29 <examples-home href=
<!--#expand-next-string-->"$(EXAMPLES)" />
30 <shapes-version number=
<!--#expand-next-string-->"$(SHAPES_VERSION)" />
31 <up-link><parent-namespace /></up-link>
33 <public-namespace>Shapes..Data
</public-namespace>
35 <!--#include virtual="^/toc.xml" -->
39 <p>Currently,
<str-Shapes /> provides both a dedicated type for singly linked lists,
<named-type name=
"SingleList" />, as well as the two-value-container
<named-type name=
"ConsPair" /> which can also be used to build singly linked lists. The
<str-Shapes /> kernel does not provide any functions that operate on
<named-type name=
"ConsPair" /> lists, but basic operations are defined in this extension.
</p>
40 <p>Note that
<named-type name=
"ConsPair" /> lists are by definition terminated by the empty
<named-type name=
"SingleList" />, recognized by
<binding name=
"null?" /> — or else they are just arbitrary
<named-type name=
"ConsPair" /> structures.
</p>
41 <p>There is an example with some relevance to this package which appears under
<named-type name=
"ConsPair" />.
</p>
44 <section id=
"extensions/conssupport/folds">
47 <p>Recall the fold operations that are accessed as fields of
<named-type name=
"SingleList" /> values. This extension defines these for
<named-type name=
"ConsPair" /> lists.
</p>
49 <system-binding identifier=
"foldl">
55 <p>Type of fold pile.
</p>
60 <p>Type of list elements.
</p>
69 <arg><type><template-type name=
"T" /></type></arg>
70 <arg><type><template-type name=
"E" /></type></arg>
73 <type><template-type name=
"T" /></type>
78 <arg identifier=
"nullRes"><type><template-type name=
"T" /></type></arg>
79 <arg identifier=
"lst"><type><named-type name=
"ConsPair" /></type></arg>
82 <type><template-type name=
"T" /></type>
84 <dynamic-references></dynamic-references>
92 <system-binding identifier=
"foldr">
98 <p>Type of fold pile.
</p>
103 <p>Type of list elements.
</p>
108 <arg identifier=
"op">
112 <arg><type><template-type name=
"T" /></type></arg>
113 <arg><type><template-type name=
"E" /></type></arg>
116 <type><template-type name=
"T" /></type>
121 <arg identifier=
"nullRes"><type><template-type name=
"T" /></type></arg>
122 <arg identifier=
"lst"><type><named-type name=
"ConsPair" /></type></arg>
125 <type><template-type name=
"T" /></type>
127 <dynamic-references></dynamic-references>
135 <system-binding identifier=
"foldsl">
141 <p>Type of fold pile.
</p>
146 <p>Type of list elements.
</p>
149 <template-state name=
"S">
151 <p>Type of state.
</p>
156 <arg identifier=
"op">
160 <arg><type><template-type name=
"T" /></type></arg>
161 <arg><type><template-type name=
"E" /></type></arg>
162 <state><type><template-state-type name=
"S" /></type></state>
165 <type><template-type name=
"T" /></type>
170 <arg identifier=
"nullRes"><type><template-type name=
"T" /></type></arg>
171 <state identifier=
"state"><type><template-state-type name=
"S" /></type></state>
172 <arg identifier=
"lst"><type><named-type name=
"ConsPair" /></type></arg>
175 <type><template-type name=
"T" /></type>
177 <dynamic-references></dynamic-references>
179 <p>Left fold with state.
</p>
185 <system-binding identifier=
"foldsr">
191 <p>Type of fold pile.
</p>
196 <p>Type of list elements.
</p>
199 <template-state name=
"S">
201 <p>Type of state.
</p>
206 <arg identifier=
"op">
210 <arg><type><template-type name=
"T" /></type></arg>
211 <arg><type><template-type name=
"E" /></type></arg>
212 <state><type><template-state-type name=
"S" /></type></state>
215 <type><template-type name=
"T" /></type>
220 <arg identifier=
"nullRes"><type><template-type name=
"T" /></type></arg>
221 <state identifier=
"state"><type><template-state-type name=
"S" /></type></state>
222 <arg identifier=
"lst"><type><named-type name=
"ConsPair" /></type></arg>
225 <type><template-type name=
"T" /></type>
227 <dynamic-references></dynamic-references>
229 <p>Right fold with state.
</p>
236 </section> <!-- End of -->
238 <section id=
"extensions/conssupport/misc">
239 <title>Miscellaneous
</title>
241 <p>Here are the functions that have no corresponding function for
<named-type name=
"SingleList" /> in the kernel.
</p>
243 <system-binding identifier=
"consify">
247 <arg identifier=
"lst">
248 <type><named-type name=
"SingleList" /></type>
252 <type><named-type name=
"ConsPair" /></type>
254 <dynamic-references></dynamic-references>
256 <p>Convert from of type of list to the other.
</p>
262 <system-binding identifier=
"map">
268 <p>Type of original list elements.
</p>
273 <p>Type of new list elements.
</p>
282 <arg><type><template-type name=
"E" /></type></arg>
285 <type><template-type name=
"T" /></type>
290 <arg identifier=
"lst"><type><named-type name=
"ConsPair" /></type></arg>
293 <type><named-type name=
"ConsPair" /></type>
295 <dynamic-references></dynamic-references>
297 <p>Construct new list with elements obtained by applying
<arg name=
"f" /> to the corresponding element in
<arg name=
"lst" />.
</p>
303 <system-binding identifier=
"sublist">
307 <arg identifier=
"lst">
308 <type><named-type name=
"SingleList" /></type>
311 <type><named-type name=
"Integer" /></type>
315 <type><named-type name=
"ConsPair" /></type>
317 <dynamic-references></dynamic-references>
319 <p>Construct list with just the first
<arg name=
"n" /> elements in
<arg name=
"lst" /> (or all of
<arg name=
"lst" /> if
<arg name=
"n" /> exceeds the length of the list). Obviously,
<arg name=
"n" /> shall be non-negative.
</p>
327 </section> <!-- End of -->