%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Reference: Chapter 11, "Concepts, Techniques, %%% and Models of Computer Programming" %%%%% 1. Open distribution - sharing records % First process declare X=the_novel(text:"It was a dark and stormy night." author:"E.G.E. Bulwer-Lytton" year:1803) {Browse {Connection.offerUnlimited X}} % Second process declare X2={Connection.take 'x-ozticket://127.0.0.1:9000:RFeiky:Mt/v:w:w:m:VXD1hv'} {Browse X2} {Browse X} %%%%%% 2. Sharing functions % First process declare fun {MyEncoder X} (X*4449+1234) mod 33667 end {Browse {Connection.offerUnlimited MyEncoder}} % Second process declare E2={Connection.take 'x-ozticket://127.0.0.1:9000:RFeiky:Mt/w:w:w:m:7vECay'} {Browse {E2 10000}} % Call the function %%%%% 3. Sharing dataflow variables % First process declare X in {Browse {Connection.offerUnlimited X}} % Second process declare X in X={Connection.take '...Xs ticket...'} {Browse X*X} X=100 declare S in {Browse {Connection.offerUnlimited S}} {Browse S} S=1|2|3|4|_ %%%%% 4. Sharing state (cells) % First process declare C={NewCell 0} {Browse {Connection.offerUnlimited C}} C:=10001 for I in 1..100 do C:=@C+1 end {Browse @C} % Second process declare C1={Connection.take '...Cs ticket...'} %%%%% 5. Sharing objects % First process declare class Coder attr seed meth init(S) seed:=S end meth get(X) X=@seed seed:=(@seed*1234+4449)mod 33667 end end C={New Coder init(100)} {Browse {Connection.offerUnlimited C}} {Browse {C get($)}} % Second process declare C2={Connection.take '...Cs ticket...'} {Browse {C2 get($)}} %%%%% 5a. Distributed lexical scoping %%%%% 6. Ticket distribution % Making tickets available through a file % Define Offer and Take, to be used from now on declare proc {Offer X FN} {Pickle.save {Connection.offerUnlimited X} FN} end fun {Take FN} {Connection.take {Pickle.load FN}} end %%%%% 7. Stream communication % First process declare Xs Sum in {Offer Xs tickfile} fun {Sum Xs A} case Xs of X|Xr then {Sum Xr A+X} [] nil then A end end {Browse {Sum Xs 0}} local Xs Sum in {Offer Xs tickfile} fun {Sum Xs A} case Xs of X|Xr then {Sum Xr A+X} [] nil then A end end {Browse {Sum Xs 0}} end % Second process declare Xs Generate in Xs={Take tickfile} fun {Generate N Limit} if N