Commit 4fc58f4c 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 91ab8526
...@@ -75,7 +75,7 @@ when static-typing enforces this property. ...@@ -75,7 +75,7 @@ when static-typing enforces this property.
</p> </p>
<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 can do is to decompose values into subcomponents that are either captured
by a variable or checked against a type. by a variable or checked against a type.
</p> </p>
...@@ -123,13 +123,13 @@ let domain (Email->String) <_>[ _*? d::(Echar+ '.' Echar+) ] -> d ...@@ -123,13 +123,13 @@ let domain (Email->String) <_>[ _*? d::(Echar+ '.' Echar+) ] -> d
]]></sample> ]]></sample>
<p> <p>
returns the last two parts of the domain of an e-mail (the <code>*?</code> 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 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 operators <code>*</code> or <code>+</code>, or if the same variable
appears several times in a regular expression, appears several times in a regular expression,
then the variable is bound to then the variable is bound to
the concatenation of all the corresponding matches. This is one of the 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 define patterns that in a single match capture subsequences of
non-consecutive elements. For instance: non-consecutive elements. For instance:
</p> </p>
...@@ -142,7 +142,7 @@ let agendaitem (Person -> PhoneItem) ...@@ -142,7 +142,7 @@ let agendaitem (Person -> PhoneItem)
<p> <p>
transforms a <code>person</code> element into a record value with two fields containing 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 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 sequence of all <code>Tel</code> elements appearing in the person. By the same rationale the pattern
</p> </p>
<sample><![CDATA[ <sample><![CDATA[
...@@ -173,9 +173,9 @@ modifications. It suffices to use a pattern regular expression to strip off ...@@ -173,9 +173,9 @@ modifications. It suffices to use a pattern regular expression to strip off
the possible occurrence of a dash: the possible occurrence of a dash:
</p> </p>
<sample><![CDATA[ <sample><![CDATA[
let agendaitem2 (Person -> \{name=String; phones=[Int*]\}) let agendaitem2 (Person -> {name=String; phones=[Int*]})
<person>[ <name>n _ (t::Tel|_)* ] -> <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> ]]></sample>
<p> <p>
In this case <code>s</code> extracts the subsequence formed only by numerical 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