HP Wei wrote:
I hit a metal block when trying to understand
Figure 9.3 in chapter 9 in the Tutorial of Oz on the mozart web site.
Here is the snippet that I copied from Figure 9.3 (with irrelevant part
deleted).
declare P S in
local
Tag = {NewName}
fun {NewPort S}
C = {NewCell S} in
{NewChunk port(Tag:C)}
end
proc {Send P M}
Ms Mr in
{Exchange P.Tag Ms Mr}
%%% point C
Ms = M|Mr %%% point D
end
in
P = {NewPort S}
{Send P 1} %%% point A
{Send P 2} %%% point B
end
------------------------------------
At point A, S contains "1"|_
After point B, S contains "1"|"2"|_
Hi HP
Here some explanation to your questions.
It is at the point C and D that I could not figure out what happened.
Suppose we are at point B when {Send P 2} is just invoked.
You should start considering what happens from point A going into Point
C. You will see why.
When the process reaches point C,
I thouhgt S should contain "1"|_
that's right
then Ms should be bind to "1"|_
Here is the confusion. When you sent 1 to the port in point A, you took
the variable S out of the cell, bind it to 1|Mr and put Mr into the
cell, then, Mr is the unbound tail of S. So, what you always keep in the
cell, is the current unbound tail of S. I hope I can do a nice drawing
of this.
S = |
/ \
1 _ <---- C
So at point C, Ms will be bound to the contain of the cell (the unbound
tail of S).
and Mr is bind to "|_
Mr is just a fresh variable that will become the new unbound tail of the
stream, that's why we put it in the cell.
and M is bind to "2"
this is right
Does the Exchange function do the exchange at this point ?
i.e.
S becomes "|_
I hope the answer to this is clear already.
what happens at point D ?
[ i.e. I don't follow the statement D with the above bindings!! ]
So we have the drawing again (use currier font to see it).
Ms got previously the content of C, and we have put Mr in C
S = |
/ \
1 _ <----Ms C := Mr
Then you bind Ms = 2|Mr, this mean that the stream S is now 1|2|Mr with
Mr kept inside C, ready to be bound to the new message. I hope is clear now.
cheers
Boriss
thanks
HP
_________________________________________________________________________________
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