Hi, Dan! Don't mention it.

Let's forget about 'case' because you seem to know what it means.

> Also, I don't understand what happens when more
> than one guard of an 'or' succeeds. Does one
> "win"?

Nope. The or statement at issue then proves to serve one single purpose:
not to fail.

>Does something bad happen? Also the case
> where *no* guards hold: what occurs in this case?

Failure ensues, which is something to be understood within the framework
of (concurrent constraint) logic programming. In other words, a special
kind of exception is raised to signal that during search the current
assumptions won't lead to a solution.

Intuitively, a command like

or S1 [] S2 [] ... [] SN end

means that at least one of S1, S2, ..., SN should be true. So if N-1
guards are known to be failed, the remaining guard is "commited to" even
if its status (failed or entailed=true) is not know at the moment. For
example, imagine that you would like to express that either a set variable
is empty or it contains at least a specific element X. That could be
achieved among others by:

------------
declare
proc {EmptyOrIncludes X Set}
   thread
      or
         Set = FS.value.empty % (1)
      []
         {FS.include X Set} % (2)
      end
   end
end
------------

Now consider the following block of constraints:

------------
declare
Set = {FS.var.decl} % declares set variable
{EmptyOrIncludes 1 Set}
{FS.card Set} >: 0 % (3) constrains S not to be empty
{Browse Set}
------------

You see, guard (1) is made failed by constraint (3). So even if we cannot
yet tell whether Set includes element 1 (i.e. we don't know whether guard
(2) is either failed or entailed by the constraint store), guard (2) is
commited to and thus Set comes to include 1. Now the following block will
raise failure:

------------
declare
Set = {FS.var.decl} % declares set variable
{EmptyOrIncludes 1 Set}
Set = {FS.value.make [3 4 5]} % let Set = {3, 4, 5}
------------

Finally, if one guard is entailed (proved to be true) according to the
constraint store (of the space that issued the 'or') then the 'or'
statement is also done with (remeber the intuitive reading above). If all
guards fail, the statement raises failure for its space.

This is pretty much it for 'or'. Now 'cond' just executes some statement
based on detection of (i) entailment of some guard ('then' clauses) or
failure of all guards ('else' clause). For a simplistic example also using
sets:

------------
declare
proc {Test Id#Set}
   thread
      cond
         {FS.card Set} = 0 % guard (1)
      then {Browse empty(Id)}
      []
         {FS.include 1 Set} % guard (2)
         {FS.include 2 Set}
      then {Browse has1And2(Id)}
      []
         {FS.include 3 Set} % guard (3)
      then {Browse has3(Id)}
      else {Browse 'else'(Id)}
      end
   end
end
S1 = {FS.var.decl}
S2 = {FS.var.decl}
S3 = {FS.var.decl}
{ForAll [s1#S1 s2#S2 s3#S3] Test}
S4 = {FS.value.make [1 2 3]} % let S4 = {1, 2, 3}
{FS.subset S4 S1} % either (2) or (3) "wins", impossible to tell which
S2 = FS.value.empty
{FS.subset S3 {FS.compl S4}} % S3 subsumed by complement of S4
{FS.card S3} >: 0
% if you exclude this line, the 'cond' statement
% won't know yet whether guard (1) is failed.
------------

Anyway, the subject is far from exhausted. I admit that this "bit" of Oz
was the hardest for me to grasp. Once again I advise you: you'll only
really get it once you've understood constraint programming in Oz and the
role of (computational) spaces therein. Unfortunately, spaces are the
worst documented feature in the tutorials, but there are plenty of (not so
newbie-friendly, I'm afraid) other sources. But start with constraint
programming before looking beyond the tutorials.

Cheers,

Jorge.

> I'm trying to experiment with the implementation
> but its difficult to grasp this part, so thanks for your help.
>
> Dan
>




_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to