/[svn]/web/memento.xml
ViewVC logotype

Contents of /web/memento.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1232 - (hide annotations)
Tue Jul 10 18:33:05 2007 UTC (5 years, 10 months ago) by abate
File MIME type: text/xml
File size: 10127 byte(s)
[r2004-07-07 01:24:40 by beppe] added select and projections

Original author: beppe
Date: 2004-07-07 01:24:40+00:00
1 abate 254 <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
2 abate 341 <page name="memento">
3 abate 254
4 abate 679 <title>Quick reference</title>
5 abate 254
6 abate 341 <left>
7     <p>This page briefly presents the syntax of the CDuce language.</p>
8     <boxes-toc/>
9     <p>See also:</p>
10 abate 684 <local-links href="index,proto,manual,tutorial,papers"/>
11 abate 341 </left>
12 abate 254
13     <box title="Identifiers" link="id">
14     <ul>
15     <li> Type and Pattern identifiers: words formed by of unicode letters and and
16     the underscore "_" character, starting by a capitalized letter. </li>
17    
18     <li> value identifiers: words formed by of unicode letters and the underscore "
19     _" character, starting by a capitalized letter or underscore.</li>
20     </ul>
21     </box>
22    
23     <box title="Scalars" link="scalars">
24     <ul>
25     <li>Large integers:
26     <ul>
27 abate 341 <li>Values: <code>0,1,2,3,...</code> </li>
28     <li>Types: intervals <code>-*--10, 20--30, 50--*, ...</code>,
29     singletons <code>0,1,2,3,...</code> </li>
30     <li>Operators: <code>+,-,/,*,div,mod, int_of</code> </li>
31 abate 254 </ul>
32     </li>
33     <li>Unicode characters:
34     <ul>
35 abate 341 <li>Values: <code>'a','b','c'...</code> </li>
36     <li>Types: intervals <code>'a'--'z', '0'--'9'</code>,
37     singletons <code>'a','b','c',...</code> </li>
38 abate 254 </ul>
39     </li>
40     <li>Symbolic atoms:
41     <ul>
42 abate 341 <li>Values: <code>`A, `B, `a, `b, `true, `false, ...</code> </li>
43     <li>Types: singletons <code>`A, `B, ...</code> </li>
44     <li>Operators: <code>atom_of</code> : String -> Atom</li>
45 abate 554 <li>CDuce also supports <local href="namespaces">XML Namespaces</local></li>
46 abate 254 </ul>
47     </li>
48     </ul>
49     </box>
50    
51     <box title="Operators" link="op">
52     <ul>
53     <li>Infix:
54 abate 388 <br/> <code>@</code> : concatenation of sequences
55 abate 341 <br/> <code>+,*,-,div,mod</code> : Integer,Integer -> Integer
56     <br/> <code>=, &lt;&lt;, &lt;=, &gt;&gt;, &gt;= </code> :
57 abate 701 <i>t</i>,<i>t</i> -> Bool = <code>`true | `false</code> (any non functional type <i>t</i>)
58 abate 722 <br/> <code>||, &amp;&amp;</code> : Bool,Bool -> Bool
59     <br/> <code>not</code>: Bool -> Bool
60 abate 254 </li>
61     <li>Prefix:
62 abate 1229 <br/><code>load_xml</code> : Latin1 -> Any,
63     <br/><code>load_html</code> : Latin1 -> [ Any* ],
64     <br/><code>load_file</code> : Latin1 -> Latin1,
65     <br/><code>load_file_utf8</code> : Latin1 -> String,
66 abate 1203 <br/><code>argv</code> : [] -> [ String* ],
67 abate 1229 <br/><code>dump_to_file</code> : Latin1 -> String -> [],
68     <br/><code>dump_to_file_utf8</code> : Latin1 -> String -> [],
69 abate 1203 <br/><code>print_xml</code> : Any -> Latin1,
70     <br/><code>print_xml_utf8</code> : Any -> String,
71 abate 1229 <br/><code>print</code> : Latin1 -> [],
72 abate 1203 <br/><code>int_of</code> : String -> Integer,
73     <br/><code>string_of</code> : Any -> Latin1,
74     <br/><code>atom_of</code> : String -> Atom
75 abate 254 </li>
76     </ul>
77     </box>
78    
79     <box title="Pairs" link="pair">
80     <ul>
81 abate 341 <li>Expressions: <code>(e1,e2)</code> </li>
82     <li>Types and patterns: <code>(t1,t2)</code> </li>
83 abate 254 <li>Note: tuples are right-associative pairs; e.g.:
84 abate 341 <code>(1,2,3)=(1,(2,3))</code> </li>
85 abate 254 <li>When a capture variable appears on both side of a pair pattern,
86     the two captured values are paired
87 abate 341 together (e.g. <code>match (1,2,3) with (x,(_,x)) -> x ==>
88     (1,3)</code>). </li>
89 abate 254 </ul>
90     </box>
91    
92     <box title="Sequences" link="seq">
93     <ul>
94 abate 341 <li>Expressions: <code>[ 1 2 3 ]</code>,
95     which is syntactic sugar for <code>(1,(2,(3,`nil)))</code> </li>
96     <li>A sub-sequence can be escaped by !: <code>[ 1 2 ![ 3 4 ] 5
97     ]</code> is then equal to <code>[ 1 2 3 4 5 ]</code> . </li>
98     <li>Types and patterns : <code>[ R ]</code> where <code>R</code> is
99 abate 254 a regular expression built on types and patterns:
100     <ul>
101     <li>A type or a pattern is a regexp by itself, matching a single
102     element of the sequence </li>
103 abate 341 <li>Postfix repetition operators: <code>*,+,?</code>
104     and the ungreedy variants (for patterns) <code>*?, +?
105     ,??</code></li>
106 abate 254 <li>Concatenation of regexps</li>
107 abate 341 <li>For patterns, sequence capture variable <code>x::R</code> </li>
108 abate 254 </ul>
109     </li>
110     <li>It is possible to specify a tail, for expressions, types, and patterns;
111 abate 341 e.g.: <code>[ x::Int*; q ]</code> </li>
112     <li>Map: <code>map e with p1 -> e1 | ... | pn -> en</code>.
113 abate 254 Each element of e must be matched. </li>
114 abate 341 <li>Transform: <code>transform e with p1 -> e1 | ... | pn -> en</code>.
115 abate 254 Unmatched elements are discarded; each branch returns a sequence
116     and all the resulting sequences are concatenated together. </li>
117 abate 1232 <li>Selection: : <code>select %%e%% from %%p1%% in %%e1%% ... %%pn%%
118     in %%en%% where %%e'%%</code>. SQL-like selection with the possibility
119     of using CDuce patterns instead of variables. <code>%%e1%% ...
120     %%en%%</code> must be sequences and <code>%%e'%%</code> a boolean
121     expression.</li>
122 abate 341 <li>Operators: concatenation <code>e1 @ e2 = [ !e1 !e2 ]</code>,
123     flattening <code>flatten e = transform e with x -> x</code>.
124 abate 254 </li>
125     </ul>
126     </box>
127    
128     <box title="Record" link="record">
129     <ul>
130 abate 1232 <li>Records literal <code>{ l1 = e1; ...; ln = en }</code></li>
131 abate 341 <li>Types: <code>{| l1 = t1; ...; ln = tn |}</code> (closed, no more
132     fields allowed), <code>>{ l1 = t1; ...; ln = tn }</code> (open,
133     any other field allowed). Optional fields: <code>li =? ti</code>
134     instead of <code>li = ti</code>.</li>
135     <li>Record concatenation: <code>e1 + e2</code>
136 abate 254 (priority to the fields from the right argument) </li>
137 abate 341 <li>Field removal: <code>e1 \ l</code> (does nothing if the
138     field <code>l</code> is not present)</li>
139     <li>Field access: <code>e1 . l</code></li>
140     <li>Record: <code>{ l1 = p1; ...; ln = pn }</code></li>
141 abate 554 <li>Labels are in fact Qualified Names (see <local href="namespaces"/>)</li>
142 abate 254 </ul>
143     </box>
144    
145     <box title="Strings" link="string">
146     <ul>
147     <li>Strings are actually sequences of characters.</li>
148 abate 341 <li>Expressions: <code>"abc", [ 'abc' ], [ 'a' 'b' 'c' ]</code>. </li>
149     <li>Operators: <code>string_of, print, dump_to_file</code></li>
150     <li><code>PCDATA</code> means <code>Char*</code> inside regular expressions</li>
151 abate 254 </ul>
152     </box>
153    
154     <box title="XML elements" link="xml">
155     <ul>
156 abate 341 <li>Expressions: <code> &lt;(tag) (attr)>content</code> </li>
157     <li>If the tag is an atom <code>`X</code>, it can be written
158     <code>X</code> (without the <code>(..)</code>).
159 abate 254 Similarly, parenthesis and curly braces may be omitted
160 abate 563 when attr is a record <code>l1=e1;...;ln=en</code>
161     (semicolon can also be omitted in this case).
162 abate 341 E.g: <code>&lt;a href="abc">[ 'abc' ]</code>.</li>
163 abate 254 <li>Types and patterns: same notations.</li>
164 abate 1232 <li>XPath like projection: <code>%%e%%/%%t%%</code>. For every
165     XML tree in <code>%%e%%</code> it returns the sequence of children
166     of type <code>%%t%%</code></li>
167 abate 775 <li>Tree transformation: <code>xtransform e with p1 -> e1 | ... | pn -> en</code>.
168     Applies to sequences of XML trees. Unmatched elements are left unchanged and the
169 abate 776 transformation is recursively applied to the sequence of children of the unmatched
170 abate 775 element; as for transform, each branch returns a sequence
171     and all the resulting sequences are concatenated together. </li>
172 abate 341 <li>Operators: <code>load_xml : String -> Any; print_xml : Any -> String</code>
173 abate 254 </li>
174     </ul>
175     </box>
176    
177     <box title="Functions" link="fun">
178     <ul>
179     <li>Expressions:
180     <ul>
181 abate 341 <li>General form: <code>fun f (t1->s1;...;tn->sn)
182     p1 -> e1 | ... | pn -> en</code> (<code>f</code> is optional) </li>
183     <li>Simple function: <code>fun f (p : t) : s = e</code>,
184     equivalent to <code>fun f (t -> s) p -> e</code> </li>
185     <li>Multiple arguments: <code>fun f (p1 : t1, p2 : t2,...) : s =
186     e</code>, equivalent to <code>fun f ((p1,p2,...):(t1,t2,...)) : s
187 abate 1110 = e</code> (note the blank spaces around colons to avoid ambiguity
188     with namespaces) </li>
189     <li>Currified function: <code>fun f (p1 : t1) (p2 : t2) ... : s =
190     e</code> (can be combined with the multiple arguments syntax).</li>
191 abate 254 </ul>
192     </li>
193 abate 341 <li>Types: <code>t -> s</code> </li>
194 abate 254 </ul>
195     </box>
196    
197     <box title="Pattern matching, exceptions, ..." link="match">
198     <ul>
199 abate 341 <li>Type restriction: <code>(e : t)</code> (forgets any more precise
200 abate 794 type for <code>e</code>; note the blank spaces around colons to avoid ambiguity with namespaces) </li>
201 abate 341 <li>Pattern matching: <code>match e with p1 -> e1 | ... | pn ->
202     en</code></li>
203     <li>Local binding: <code>let p = e1 in e2</code>, equivalent to
204     <code>match e1 with p -> e2</code>;
205     <code>let p : t = e1 in e2</code> equivalent to
206     <code>let p = (e1 : t) in e2</code> </li>
207     <li>If-then-else: <code>if e1 then e2 else e3</code>, equivalent to
208     <code>match e1 with `true -> e2 | `false -> e3</code></li>
209 abate 254 <li>Exceptions: <ul>
210 abate 341 <li>Raise exception: <code>raise e</code></li>
211     <li>Handle exception: <code>try e with p1 -> e1 | ... | pn ->
212     en</code></li>
213 abate 254 </ul> </li>
214     </ul>
215     </box>
216    
217     <box title="More about types and patterns" link="type">
218     <ul>
219 abate 341 <li>Boolean connectives: <code>&amp;,|,\</code> (<code>|</code> is
220 abate 254 first-match). </li>
221 abate 341 <li>Empty and universal types: <code>Empty,Any</code> or
222     <code>_</code>.</li>
223     <li>Recursive types and patterns: <code>t where T1 = t2 and ... and
224     Tn = tn</code>.</li>
225     <li>Capture variable: <code>x</code>. </li>
226     <li>Default values: <code>(x := c)</code>. </li>
227 abate 254 </ul>
228     </box>
229 abate 282
230 abate 630 <box title="References" link="ref">
231    
232     <ul>
233     <li>Type: <code>ref %%T%%</code>.</li>
234     <li>Construction: <code>ref %%T%% %%e%%</code>.</li>
235     <li>Dereferencing: <code>!%%e1%%</code>.</li>
236     <li>Assignment: <code>%%e1%% := %%e2%%</code>.</li>
237     </ul>
238    
239     </box>
240    
241 abate 341 <box title="Toplevel statements" link="toplevel">
242 abate 282 <ul>
243 abate 554 <li>Global expression to evaluate.</li>
244     <li>Global let-binding.</li>
245     <li>Global function declaration.</li>
246 abate 341 <li>Type declarations: <code>type T = t</code>.</li>
247 abate 554 <li>Global <local href="namespaces">namespace</local>:
248     <code>namespace p = "..."</code>,
249     <code>namespace "..."</code>.</li>
250     <li>Source inclusion: <code>include %%filename_string%%</code>.</li>
251     <li>Debug directives: <code>debug %%directive argument%%</code> <br/>
252     where <code>%%directive%%</code> is one of the following: <code>accept</code>,
253     <code>subtype</code>, <code>compile</code>, <code>sample</code>, <code>filter</code>.
254 abate 282 </li>
255 abate 554 <li>Toplevel directives: <code>#env</code>, <code>#quit</code>,
256     <code>#reinit_ns</code>.</li>
257 abate 282 </ul>
258     </box>
259    
260 abate 254 </page>

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5