Her's a simpler version.
proc {IsMember X Xs}
H1 Tail in
Xs = H1 | Tail
choice H1 = X [] {IsMember X Tail} end
end
One can test to ensure that Xs is not an empty list with Xs = H1 | Tail as a guard. It just can't be done with a case statement. (The case statement is going to kill me. I keep trying to use it for things it's not intended to do.)
On 10/3/05, Russ Abbott <[EMAIL PROTECTED]> wrote:
Well, I went home and had dinner and ran it again, this time without Ozcar. It ran just fine. I got [1 2 3 4 5] as output. Then I turned on Ozcar and got a yellow thread with no output again.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 22I guess that's to be expected, but shouldn't SearchAll suppress that? Isn't that sort of thing how SearchAll knows to stop?When I added 'else skip' to my case statement, I got [1 2 3 4 5 _], which is not what one wants.I guess that could be fixed with some ugly coding, matching to X1 X2 | Tail in one case and [X1] in the other. But one shouldn't have to do that.This, finally, works.local
proc {IsMember X Xs}
case Xs of H1 | (H2 | Tail) then
choice H1 = X [] {IsMember X H2 | Tail} end
[] [H] then X = H
end
end
in
{Browse {SearchAll proc {$ Y} {IsMember Y [1 2 3 4 5]} end}}
end-- RussP.S. In the course of getting this to run I found out that H1 H2 | Tail is not valid syntax as the equivalent is in Prolog. It doesn't work with parentheses either: (H1 H2 | Tail)
On 10/3/05, Russ Abbott <[EMAIL PROTECTED] > wrote:I'm still trying to use Oz like Prolog, and I'm still confused. For example, I was hoping that if X is unbound the following would bind it to elements of Xs.
proc {IsMember X Xs}
case Xs of
Head | Tail then
choice
Head = X
[] {IsMember X Tail}
end
end
end
If I run{IsMember Y [1 2 3 4 5]}
{Browse Y}Ozcar tells me that I get to the 'end' at the bottom of the choice statement with X bound to 1. At that point the thread turns yellow, saying that it is running. What is it waiting for?If instead I run
{Browse {SearchAll proc {$ Y} {IsMember Y [1 2 3 4 5]} end}}the thread turns yellow when it enters SearchAll. Why don't I get all members of the list as the SearchAll answer?Thanks.-- Russ
--
_____________________________________________
Professor, Computer Science
California State University, Los Angeles
o Check out my blog at http://russabbott.blogspot.com/
_________________________________________________________________________________ mozart-users mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-users
