%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% 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:"Ex.G.E. Bulwer-Lytton" year:1803) {Show {Connection.offerUnlimited X}} % Second process declare X2={Connection.take '...ticket comes here...'} %%%%%% 2. Sharing functions % First process declare fun {MyEncoder X} (X*4449+1234) mod 33667 end {Show {Connection.offerUnlimited MyEncoder}} % Second process declare E2={Connection.take '...MyEncoders ticket...'} {Show {E2 10000}} % Call the function %%%%% 3. Sharing dataflow variables % First process declare X in {Show {Connection.offerUnlimited X}} % Second process declare X in X={Connection.take '...Xs ticket...'} {Browse X*X} X=100 declare S in {Show {Connection.offerUnlimited S}} {Browse S} S=1|2|3|4|_ %%%%% 4. Sharing state (cells) % First process declare C={NewCell 0} {Show {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 inc(X) X=@seed seed:=@seed+1 end meth get(X) X=@seed seed:=(@seed*1234+4449)mod 33667 end end C={New Coder init(100)} {Show {Connection.offerUnlimited C}} {Browse {C inc($)}} {Browse start} for I in 1..100000 do {C inc(_)} end {Browse stop} % 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