Two beginner questions
Urban Hafner
urban.hafner at stud.ifi.lmu.de
Fri Jan 21 18:26:50 CET 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hej everybody,
I'm currently learning Oz while reading Concepts, Techniques, and Models
of Computer Programming. While making the exercises of chapter 1 I
managed to write two bits of code that don't work like I want them to. I
hope someone can tell me what I'm doing wrong.
When I try to compile this bit of code:
declare Accum in
local C in
~ C={NewCell 0}
~ fun {Accum N}
~ D=@C
~ in
~ if N<=D
C:=D+N
~ else
C:=D-N
~ end
~ @C
~ end
end
I get this error message:
%*************************** parse error ************************
%**
%** expecting `then'
%**
%** in file "/Users/urban/blog/book/CTMCP/parse-error.oz", line 7, column 10
%** ------------------ rejected (1 error)
Seems like it doesn't like the 'if' after the 'in'. What's wrong here?
The second one one compiles just fine but I hangs in the 'A={NewStore}'
line. What's wrong here?
declare
fun {NewStore}
~ Cell Put Get Size SizeI in
~ Cell:={NewCell nil}
~ SizeI:={NewCell 0}
~ proc {Put N I}
~ fun {PutHelper S N I}
case S of Num|Val|T then
if Num==N then
N|I|T
else
Num|Val|{PutHelper T N I}
end
else
SizeI:=@SizeI+1
N|I|S
end
~ end
~ in
~ Cell:={PutHelper @Cell N I}
~ end
~ fun {Get N}
~ fun {GetHelper S N}
case S of Num|Val|T then
if Num==N then
Val
else
{GetHelper T N}
end
else
nil
end
~ end
~ in
~ {GetHelper @Cell N}
~ end
~ fun {Size}
~ @SizeI
~ end
~ store(put:Put get:Get size:Size)
end
declare A in
{Browse 0}
A={NewStore}
{Browse 1}
{Browse {A.size}}
{Browse 2}
{A.put 2 [22 23]}
{Browse 3}
{A.put 1 [21 243]}
{Browse 4}
{Browse {A.get 1}}
{Browse 5}
Thanks for your help,
Urban
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Darwin)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFB8TtaggNuVCIrEyURAoULAKCC1DtqBbg4l60OrvZVcz8S25uCEACfa00D
iiOtridCDH20MUEL415xgLM=
=nb1Y
-----END PGP SIGNATURE-----
More information about the mozart-users
mailing list