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
6ac91be1
Commit
6ac91be1
authored
Jul 10, 2007
by
Pietro Abate
Browse files
[r2005-06-25 12:54:15 by beppe] added dynamic type check
Original author: beppe Date: 2005-06-25 12:54:15+00:00
parent
0ab0a470
Changes
1
Hide whitespace changes
Inline
Side-by-side
web/tutorial/getting_started.xml
View file @
6ac91be1
...
...
@@ -272,19 +272,28 @@ type <code>ParentBook</code>) then it performs the assignment (the variable
<code>
x
&
ParentBook
</code>
) otherwise it raises an exception.
</p>
<p>
Of course an exception such as "parents.xml is not a document of type ParentBook" it is not
very informative about why the document failed the match an where the error might be. In CDuce it is
possible to ask the program to perform this check and raise an informative exception (a string
that describes and localize the problem) by using the dynamic type check construction
<code>
(%%e%%:?%%t%%)
</code>
which
checks whether the expression
<code>
%%exp%%
</code>
has type
<code>
%%t%%
</code>
and it either returns the result of
<code>
%%exp%%
</code>
or raise an informative exception. The dynamic type check can be also used in a let construction as follows
Of course an exception such as "parents.xml is not a document of type
ParentBook" it is not very informative about why the document failed the match
an where the error might be. In CDuce it is possible to ask the program to
perform this check and raise an informative exception (a string that describes
and localize the problem) by using the dynamic type check construction
<code>
(%%e%%:?%%t%%)
</code>
which checks whether the expression
<code>
%%exp%%
</code>
has type
<code>
%%t%%
</code>
and it either returns the
result of
<code>
%%exp%%
</code>
or raise an informative exception.
</p>
<sample>
<![CDATA[
let parents
:? ParentBook
= load_xml "parents.xml"
let parents = load_xml "parents.xml"
:? ParentBook
]]>
</sample>
<p>
which
does
the same test as the previous program but in case of failure give
which
perform
the same test as the previous program but in case of failure give
information to the programmer on the reasons why the type check failed.
The dynamic type check can be also used in a let construction as follows
</p>
<sample>
<![CDATA[
let parents :? ParentBook = load_xml "parents.xml"
]]>
</sample>
<p>
which is completely equivalent to the previous one.
</p>
<p>
The command
<code>
load_xml "parents.xml"
</code>
is just an abbreviated form for
...
...
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