Commit fc47ebc0 authored by Pietro Abate's avatar Pietro Abate

[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 edb1fa6a
......@@ -272,19 +272,28 @@ type <code>ParentBook</code>) then it performs the assignment (the variable
<code>x&amp;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
......
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