%% dataflow variables revisited: local X Y Z in X = 5 Y = 6 Z = X+Y {Browse [X Y Z]} end local X Y Z in Z = X+Y % will block forever (X and Y are not bound, "+" suspends) X = 5 Y = 6 {Browse [X Y Z]} end local X Y Z in thread Z = X+Y end % will wait until parent thread assigns X and Y X = 5 Y = 6 {Browse [X Y Z]} end local X Y Z in thread Z = X+Y end % will wait forever for Y X = 5 Z = 6 {Browse [X Y Z]} end local X Y Z in thread Z = X+Y end % after Y is assigned 1, it resumes execution: % compatible assignment "6 = 6" X = 5 Z = 6 {Browse [X Y Z]} Y = 1 end local X Y Z in thread Z = X+Y end % after Y is assigned 2, it resumes execution: % incompatible assignment "6 = 7" displays failure % but store assignments remain X=5 Y=6 Z=2 X = 5 Z = 6 {Browse [X Y Z]} Y = 2 end % failures halt execution of a composite statement, e.g.: local X Y Z in thread Z = X+Y % after Y is assigned 2, it resumes execution: % incompatible assignment "6 = 7" displays failure {Browse Z} % Z is not displayed. end X = 5 Z = 6 {Browse [X Y Z]} Y = 2 end local X Y Z in thread Z = X+Y % after Y is assigned 1, it resumes execution: % compatible assignment "6 = 6" {Browse Z} % Z is displayed. end X = 5 Z = 6 {Browse [X Y Z]} Y = 1 end % %% On recursive computation % %sumlist declare fun {SumList L} case L of nil then 0 [] X|L2 then X+{SumList L2} end end {Browse {SumList [1 2 3 4]}} %map declare fun {Map Xs F} case Xs of nil then nil [] X|Xr then {F X}|{Map Xr F} end end {Browse {Map [1 2 3 4] fun {$ I} I*I end}} %filter declare fun {Filter Xs P} case Xs of nil then nil [] X|Xr andthen {P X} then X|{Filter Xr P} [] _|Xr then {Filter Xr P} end end {Browse {Filter [1 2 3 4] fun {$ A} A<3 end}} %minus declare fun {Minus L X} {Filter L fun {$ V} V \= X end} end %freevars declare fun {FreeVars E} case E of app(F A) then {Append {FreeVars F} {FreeVars A}} [] lambda(V E) andthen {IsAtom V} then {Minus {FreeVars E} V} [] V andthen {IsAtom V} then [V] else raise illFormedExpression(E) end end end %iscombinator declare fun {IsCombinator E} {FreeVars E} == nil end {Browse {IsCombinator lambda(x x)}} {Browse {IsCombinator x}} {Browse {IsCombinator app(lambda(x x) y)}} {Browse {IsCombinator app(lambda(x x) x)}} {Browse {IsCombinator lambda(x app(x x))}} {Browse {IsCombinator app(lambda(x app(x x)) lambda(x app(x x)))}}