declare
proc {NewPort S P}
P = {NewCell S}
end
proc {Send P X}
S=@P S1 in
S = X|S1
P:=S1
end
A Secure unbundled stateful version
declare
proc {NewWrapper ?Wrap ?Unwrap}
Key={NewName}
in
fun {Wrap X}
fun {$ K} if K==Key then X end end
end
fun {Unwrap W}
{W Key}
end
end
declare NewPort Send
local Wrap Unwrap in
{NewWrapper Wrap Unwrap}
proc {NewPort S P}
P = {Wrap {NewCell S}}
end
proc {Send P X}
C={Unwrap P} S=@C S1 in
S = X|S1
C:=S1
end
end
A Secure Bundled stateful version
declare
proc {NewPort S P}
C = {NewCell S}
proc {Send X}
S = @C S1 in
S = X|S1
C := S1
end
in
P = port(send:Send)
end
%Usage
declare P S
{NewPort S P}
{Browse S}
{P.send a}
{P.send b}
Note: In chapter 5 it is said that end of port stream is a readonly variable, I don't completely understand the meaning of that and hence above versions don't support that statement, Someday I'll give more thought to it.
No comments:
Post a Comment