Page 1 of 1

using erroneous

Posted: 22 Oct 2010 15:51
by Paul Cerkez
Thomas,
I have created a few fact variables and initialzed them with erroneous.

my question is this, if the variable is still "erroneous" I want to take action on it and replace the erroneous with another value (could be an object ids, a populated tree, or what ever) that is not determined until runtime.

when I tried to use an if condition,

Code: Select all

input: neuron:= erroneous ... if input = erroneous then do ...
it would not compile, I would get an error back.

I created a workaround that works, but I would prefer to simply test on the 'erroneous' if possible.

any suggestions?

Posted: 22 Oct 2010 18:08
by Gildas Menier
Hi Paul,

try

Code: Select all

 if isErroneous(input) then ...
best regards

Gildas

Posted: 22 Oct 2010 21:40
by Thomas Linder Puls
erroneous is not a value, it is a state a fact variable can be in.

If you try to obtain the value of a fact which is in the erroenous state you will get an exception (your test obtains the value of the fact).

We have deliberately decided it like that because a value could "travel" far away before you noticed that it was in fact erroneous. This would lead to huge problems trying to trace back to the origin of the problem. The problem is well known from NULL pointers in languages that relies on such ones.

And as Gildas writes the solution is to use the special predicate isErroneous (which is special because it does not work on the value of the fact variable, but on the fact variable itself).

Posted: 23 Oct 2010 15:50
by Paul Cerkez
thanks Thomas and Gildas, I did not kow about the isErroneous predicate.

it defintiely solves my problem.