Commit c0b9613d authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2004-05-04 23:13:55 by beppe] Empty log message

Original author: beppe
Date: 2004-05-04 23:13:55+00:00
parent ca66ff18
......@@ -19,17 +19,17 @@ test it on the <a href="cgi-bin/cduce">online interpreter</a>.
<box title="Advanced programming" link="sel">
<p>
The fact that reference types are encoded rather than primitives have some advantaes. Noteworthy is the fact that our encoding allows the programmer to modify the default beahvior of the <code>get</code> and <code>set</code> functions can be modified. So a programmer can define a reference that whenever is read, records the access in a log file, or it performs some sanity checks before performing a writing.
The fact that reference types are encoded rather than primitive brings some advantages. Among these it is noteworthy that thanks to the encoding the default beahvior of the <code>get</code> and <code>set</code> functions can be modified. So a programmer can define a reference that whenever is read, records the access in a log file, or it performs some sanity checks before performing a writing.
</p>
<p>
For instance ... (write some code here of the form
For instance the following template program, shows a way to define a reference to an integer that whenver is read performs some extra code, while whenever is written performs some checks and may raise an exception:
</p>
<sample><![CDATA[
let x =
let hidden = ref Int 0 in
{ get = %%some extra code%%; hidden.get ;
set = function (x:Int):[]
{ get = (%%some extra code%%; hidden.get) ;
set = fun (x :Int):[] =
if %%some condition%%
then hidden.set(x)
else raise %%some exeption%%
......
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