On Mon, Oct 31, 2005 at 01:48:02PM -0800, Rukman Senanayake wrote:
> Hi all,
>
> I'm a newbie in Oz and has a problem regarding := and
> how it is supposed to update a cell
>
> The following code fails when the function F2 is
> called for the second time, due to a 'tell: ~18.0 =
> 0.0'
>
> Can anyone tell me why this is?
Make sure you understand the difference with proc and fun. The latter
is syntatic sugar for proc that expects as the last instruction an
expression and implicitly returns that as the function's value.
:= can be both a statement and an expression. You are using it as an
expression in your code since you use fun. Therefore that returns the
old value of the cell as the function's value.
Look here:
> {Browse ['T2='@T2]}
> {F Range.e 0.0}
You get an error here since you've said that the function's value will
be 0.0 but on the second call Y2's old value is ~18.0 which, indeed,
is not 0.0.
Looks like you should use proc to declare your procedures F1, F2, G1
and G2 instead of fun.
I don't think that this line will do what you expect, either:
> Succ = @T1 >= @T2 andthen @T3 >= @T4
If that ever tests false and true on different calls to Bounded you'll
get another tell error since you're trying to bind different values to
Succ.
As a general advice, think of state as a powerful tool that you should
use only when necessary. You can do more harm than good if you invoke
it needlessly. I think you could well do without with what you are
trying to do here.
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users