Without search, all one can do for IsMember is make a deterministic version IsMemberOnce/3. But it's not terrible.
local
proc {Unify X Y Z}
try X = Y Z = true
catch _ then Z = false
end
end
proc {IsMemberOnce X Xs Z}
Head Tail in
if {Unify Xs (Head | Tail)} then
if {Unify X Head} then Z = true
else {IsMemberOnce X Tail Z}
end
else Z = false
end
end
C D
in
{Browse C#{IsMemberOnce C [a b]}}
D = b
{Browse D#{IsMemberOnce D [a b]}}
end
It can also be used as a conditional in an if statement.
proc {Unify X Y Z}
try X = Y Z = true
catch _ then Z = false
end
end
proc {IsMemberOnce X Xs Z}
Head Tail in
if {Unify Xs (Head | Tail)} then
if {Unify X Head} then Z = true
else {IsMemberOnce X Tail Z}
end
else Z = false
end
end
C D
in
{Browse C#{IsMemberOnce C [a b]}}
D = b
{Browse D#{IsMemberOnce D [a b]}}
end
It can also be used as a conditional in an if statement.
-- Russ
On 10/4/05, Russ Abbott <[EMAIL PROTECTED]> wrote:
Here's what I want as an option to case--especially since choice can't be used until after one knows about Computation Spaces. I want to be able to use and teach about unification as an independent topic. It's such a powerful construct that one should be able to use it on its own. Also, it should be usable as a Boolean, i.e., does expr1 unify with expr2, which should be available as part of a control structure. So here's what I suggest.Define a proc Unify/3 that attempts to unify its first two arguments and sets its third argument to true/false depending on whether not it succeeds.local
proc {Unify X Y Z}
try X = Y Z = true
catch _ then Z = false
end
end
A B
in
if {Unify [A b a] [a B B]} then {Browse 1#A#B}
elseif {Unify [A b] [a B]} then {Browse 2#A#B}
end
endIt would be even nicer if value.'=' were defined as both =/2 and =/3, with the latter being defined as above.-- 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
