Commit 8cbb43d1 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2003-07-08 09:32:55 by cvscast] Empty log message

Original author: cvscast
Date: 2003-07-08 09:33:52+00:00
parent 8777a4e5
......@@ -75,7 +75,7 @@ when static-typing enforces this property.
</p>
<p>
These first examples already show the essence of \cduce's patterns: all a pattern
These first examples already show the essence of CDuce's patterns: all a pattern
can do is to decompose values into subcomponents that are either captured
by a variable or checked against a type.
</p>
......@@ -123,13 +123,13 @@ let domain (Email->String) <_>[ _*? d::(Echar+ '.' Echar+) ] -> d
]]></sample>
<p>
returns the last two parts of the domain of an e-mail (the <code>*?</code>
is an ungreedy version of <code>*</code>, see ??????).
is an ungreedy version of <code>*</code>, see <a href="tutorial_patterns.html#pre">regular expressions patterns</a>).
If these ::-captures are used <i>inside</i> the scope of the regular expression
operators <code>*</code> or <code>+</code>, or if the same variable
appears several times in a regular expression,
then the variable is bound to
the concatenation of all the corresponding matches. This is one of the
distinctive and powerful characteristics of \duce{}, since it allows to
distinctive and powerful characteristics of CDuce, since it allows to
define patterns that in a single match capture subsequences of
non-consecutive elements. For instance:
</p>
......@@ -142,7 +142,7 @@ let agendaitem (Person -> PhoneItem)
<p>
transforms a <code>person</code> element into a record value with two fields containing
the element's name and the list of all the phone numbers. This is
obtained thanks to the pattern <code>(t::Tel\;|\;_)*</code> that binds to <code>t</code> the
obtained thanks to the pattern <code>(t::Tel | _)*</code> that binds to <code>t</code> the
sequence of all <code>Tel</code> elements appearing in the person. By the same rationale the pattern
</p>
<sample><![CDATA[
......@@ -173,9 +173,9 @@ modifications. It suffices to use a pattern regular expression to strip off
the possible occurrence of a dash:
</p>
<sample><![CDATA[
let agendaitem2 (Person -> \{name=String; phones=[Int*]\})
let agendaitem2 (Person -> {name=String; phones=[Int*]})
<person>[ <name>n _ (t::Tel|_)* ] ->
\{ name = n; phones = map t with <tel>[(s::'0'--'9'|_)*] -> int_of s \}
{ name = n; phones = map t with <tel>[(s::'0'--'9'|_)*] -> int_of s }
]]></sample>
<p>
In this case <code>s</code> extracts the subsequence formed only by numerical
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment