The latter def is shorthand for
proc {IsMember X Xs}
case Xs of H|T then
choice X=H [] {IsMember X T} end
else
skip
end
end
Here, the else clause does nothing.
Executing a fail, on the other hand, causes the present space to fail:
the failure exception 'tells' that the space is inconsistent.
If fail is executed in some subspace (e.g. IsMember is used in some
search script given to a solver), the failure exception is caught by
the solver and reacted upon. (If executed in the top-level space, the
failure exception is visible to user -- which can be handy for
debugging.)
Best,
Torsten
On 04.10.2005, at 18:33, Russ Abbott wrote:
..., which raises the following question. What's the intended
difference between
proc {IsMember X Xs}
case Xs of H|T then
choice X=H [] {IsMember X T} end
else
fail
end
end
and
proc {IsMember X Xs}
case Xs of H|T then
choice X=H [] {IsMember X T} end
end
end
I had intended the former when I wrote the latter. Is there a real
intended semantic difference? Semantically, what does adding "else
fail" do/mean? In Prolog it (or the equivalent) does/means nothing,
which is the source of my confusion.
-- Russ
On 10/4/05, Raphael Collet <[EMAIL PROTECTED]> wrote:
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
_______________________________________________________________________
__________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users
--
Torsten Anders
Sonic Arts Research Centre
Queen's University Belfast (UK)
www.torsten-anders.de
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users