Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
8cbb43d1
Commit
8cbb43d1
authored
Jul 10, 2007
by
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
web/tutorial/first_functions.xml
View file @
8cbb43d1
...
...
@@ -75,7 +75,7 @@ when static-typing enforces this property.
</p>
<p>
These first examples already show the essence of
\cd
uce's patterns: all a pattern
These first examples already show the essence of
CD
uce'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
\d
uce
{}
, since it allows to
distinctive and powerful characteristics of
CD
uce, 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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment