..., 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
