source: project/release/3/coerce/trunk/coerce.html @ 8916

Last change on this file since 8916 was 8916, checked in by Kon Lovett, 12 years ago

Canon dir struct

File size: 5.4 KB
Line 
1<html lang="en">
2
3<head>
4<title>Coerce</title>
5<meta http-equiv="Content-Type" content="text/html">
6<meta name="description" content="Untitled">
7<meta name="generator" content="makeinfo 4.8">
8<link title="Top" rel="start" href="#Top">
9<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
10<meta http-equiv="Content-Style-Type" content="text/css">
11<style type="text/css"><!--
12  pre.display { font-family:inherit }
13  pre.format  { font-family:inherit }
14  pre.smalldisplay { font-family:inherit; font-size:smaller }
15  pre.smallformat  { font-family:inherit; font-size:smaller }
16  pre.smallexample { font-size:smaller }
17  pre.smalllisp    { font-size:smaller }
18  span.sc    { font-variant:small-caps }
19  span.roman { font-family:serif; font-weight:normal; }
20  span.sansserif { font-family:sans-serif; font-weight:normal; }
21--></style>
22</head>
23
24<body>
25
26<h3>Coerce</h3>
27
28<h3>Description</h3>
29<p>Convert an object to another representation</p>
30
31<h3>Version</h3>
32<ul>
33<li>3.001 Added composite-coerce-extension & remove-coerce-extension.</li>
34<li>3.0 Added test. Removed coerce-procedure. Added case-coerce. Added hygienic macro support.</li>
35<li>2.0 Split into syntax & support files.</li>
36<li>1.3 Added coerce-all, changed signature of default-procedure parameter.</li>
37<li>1.2 Added default-procedure parameter to coerce.</li>
38<li>1.1 Added extend.</li>
39</ul>
40
41<h3>Requires</h3>
42<ul>
43<li>miscmacros</li>
44<li>misc-extn</li>
45</ul>
46
47<h3>Usage</h3>
48<code>(require-extension coerce)</code>
49
50<h3>Documentation</h3>
51<p class="noindent">A Chicken specific version of the SLIB "coerce.scm" module, with
52extensions.</p>
53<p class="noindent">Implements object type conversion</p>
54
55<div class="defun">
56[procedure] <b>type-of</b> <var>object</var><br>
57<blockquote>
58<p>Returns a symbol name for the type of <var>object</var>.
59</p></blockquote></div>
60
61<div class="defun">
62[procedure] <b>coerce</b> <var>object</var> <var>result-type</var> <var>[default-proc]</var><br>
63<blockquote>
64<p>Converts and returns <var>object</var> to <var>result-type</var>.
65<ul>
66<li><var>result-type</var> is a symbol.</li>
67
68<li><var>default-proc</var> is <code>(-> object-type-symbol object result-type-symbol
69object)</code> and is invoked when coercion fails.</li>
70
71<li>Builtin types are <code>char</code>, <code>number</code>,
72<code>string</code>, <code>symbol</code>, <code>list</code>, and <code>vector</code>.</li>
73</ul>
74</p></blockquote></div>
75
76<div class="defun">
77[procedure] <b>coerce-all</b> <var>list-of-object</var> <var>list-of-result-type</var> <var>[default-proc]</var><br>
78<blockquote>
79<p>Returns a list of every element of <var>list-of-object</var> coerced to the corresponding
80element of <var>list-of-result-type</var>.
81<ul>
82<li><var>default-proc</var> and <var>result-type</var> are as for <code>coerce</code>.</li>
83</ul>
84</p></blockquote></div>
85
86<div class="defun">
87[procedure] <b>extend-coerce</b> <var>identifier</var> <var>predicate</var> <var>convertor</var><br>
88<blockquote>
89<p>Extends the domain of coerce with the type definition
90{<var>identifier</var> <var>predicate</var> <var>convertor</var>}.
91<ul>
92<li><var>identifier</var> is a symbol.</li>
93
94<li><var>predicate</var> is a procedure, <code>(-> object boolean)</code>,
95testing whether the argument is a type. </li>
96
97<li><var>convertor</var> is a procedure, <code>(-> object symbol
98on-error object)</code>, converting from the type to a result type.</li>
99
100<li>The <var>convertor</var> <b>must</b> invoke <var>(on-error)</var> when conversion not
101possible. Usually <code>case-coerce</code> would be used to create the
102<var>convertor</var>, which automatically handles calling of the <var>on-error</var>
103parameter.</li>
104</ul>
105</p></blockquote></div>
106
107<div class="defun">
108[procedure] <b>composite-coerce-extension</b> <var>identifier</var> <var>predicate</var> <var>convertor</var><br>
109<blockquote>
110<p>Extends the domain of an existing coerce extension.
111<ul>
112<li><var>identifier</var>, <var>predicate</var>, and <var>convertor</var> are as
113for <code>extend-coerce</code>.</li>
114
115<li>The new <var>convertor</var> is try'ed before the existing procedure,
116then the existing procedure is try'ed "on-error".</li>
117
118<li>Should the new <var>predicate</var> and existing predicate be <code>eq?</code> the
119predicates are not "composited" using <code>or</code>.</li>
120</ul>
121</p></blockquote></div>
122
123<div class="defun">
124[procedure] <b>remove-coerce-extension</b> <var>identifier</var><br>
125<blockquote>
126<p>Delete any existing coerce extension for <var>identifier</var>.
127</p></blockquote></div>
128
129<div class="defun">
130[procedure] <b>make-case-coerce</b> <var>convertor</var> <var>[alist]</var><br>
131<blockquote>
132<p>Returns a coercion procedure for use with <code>extend-coerce</code></p>
133<ul>
134<li><var>convertor</var> is a coercion procedure, <code>(-> object symbol
135on-error object)</code>.</li>
136
137<li><var>alist</var> is a list of <code>(symbol . (-> object object))</code>.</li>
138</ul>
139</p></blockquote></div>
140
141<div class="defun">
142[macro] <b>case-coerce</b> <var>case ...</var><br>
143<blockquote>
144<p>Returns a coercion procedure for use with <code>extend-coerce</code>.
145<ul>
146<li><var>case</var> is of the form <code>((symbol ...) expression ...)</code>, or <code>(else expression ...)</code></li>
147
148<li>The variable <var>object</var> is bound to the object to coerce within the case-body, <var>case ...</var>.</li>
149
150<li>The variable <var>on-error</var> is bound to a thunk within the case-body, <var>case ...</var>, to invoke on error.</li>
151</ul>
152</p></blockquote></div>
153
154</body>
155
156</html>
157
Note: See TracBrowser for help on using the repository browser.