Hi folks,

I was working Exercise 6 in Chapter 5 of CTM, and I came across a couple of
issues.

First of all, I think the last *else* line in Figure 5.22 (p. 393) needs an
*end* after it.

Secondly, contrary to Exercise 6a, I do not think the second form reduces to
the third form when the time-out delay is zero. Here's some sample Erlang:

receive
    {rectangle, [X,Y]} -> X*Y;
    {circle, [R]} -> 3.14159*R*R;
after [ 0 -> 0 ];
end

Here's the Oz translation, using the second form (with some boilerplate
added):

declare Sin Result Sout

Sin=[foo rectangle([2 3])]

Result = local
   Cancel={Alarm 0}
   fun{Loop S T#E Sout}
      if {WaitTwo S Cancel}==1 then
         case S of M|S1 then
            case M
            of rectangle([X Y]) then E=S1 T=Sout X*Y
            [] circle([R]) then E=S1 T=Sout 3.14159*R*R
            else E1 in E=M|E1 {Loop S1 T#E1 Sout} end
         end
      else E=S T=Sout 0 end
   end T
in
   {Loop Sin T#T Sout}
end

{Browse Sin#Result#Sout}

Now here's the translation of the third form (with the same boilerplate):

declare Sin Result Sout

Sin=[foo rectangle([2 3])]

Result = if {IsDet Sin} then
   case Sin of M|S1 then
       case M
       of rectangle([X Y]) then S1=Sout X*Y
       [] circle([R]) then S1=Sout 3.14159*R*R
       else Sin=Sout 0 end
   end
else Sout=Sin end

{Browse Sin#Result#Sout}

The second form gives the result [foo rectangle([2 3])]#6#[foo], but the
third form gives the result [foo rectangle([2 3])#0#[foo rectangle([2 3])].

The problem is that the third form eliminates the loop that was present in
the other two forms. I'm not sure why that facet was eliminated.

Am I missing something?

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

Reply via email to