Russ Abbott wrote:
Her's a simpler version.
proc {IsMember X Xs}
H1 Tail in
Xs = H1 | Tail
choice H1 = X [] {IsMember X Tail} end
end
Indeed, that one is correct. Moreover, Xs can also be used as an
output, while the "case" version only uses Xs as an input.
One can fix the version with the case statement. Adding the "else skip"
was a mistake because the logic semantics of "skip" is TRUE. If the
list is empty, there is no way for X to be an element of Xs. Therefore
the result in that case is "fail", whose semantics is FALSE:
proc {IsMember X Xs}
case Xs of H|T then
choice X=H [] {IsMember X T} end
else
fail
end
end
When I ran it without Ozcar, I got the right answer, but I also got
an emulator error message saying
%** Missing else clause
%**
%** Matching: nil
%** in file "Oz", line 22
This is on purpose. The program went fine, in fact. The missing "else"
clause raised an exception in the program, which made the predicate
fail. The problem is that the exception is likely to be a programmer
error instead of a real failure. Adding an explicit "fail" like above
removes any ambiguity.
Cheers,
raph
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users