% %% 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 {\$ X} X*X 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 mod 2 == 0 end}} %minus declare fun {Minus L X} {Filter L fun {\$ V} V \= X end} end {Browse {Minus [1 2 3 4] 2}} %rcurry declare RCurry = fun {\$ F} fun {\$ Y} fun {\$ X} {F X Y} end end end declare Minus = fun {\$ Xs V} {{{RCurry Filter} fun {\$ X} X \= V end } Xs} end {Browse {Minus [1 2 3 4] 2}} declare Minus2 = {{RCurry Filter} fun {\$ X} X \= 2 end } {Browse {Minus2 [1 2 3 4]}} declare MinusV = fun {\$ V} {{RCurry Filter} fun {\$ X} X \= V end } end declare Minus2 = {MinusV 2} {Browse {Minus2 [1 2 3 4]}} %freevars declare fun {FreeVars E} case E of [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 {Browse {FreeVars lambda(x x)}} {Browse {FreeVars x}} {Browse {FreeVars [lambda(x x) y]}} {Browse {FreeVars [lambda(x x) x]}} {Browse {FreeVars lambda(x [x x])}} {Browse {FreeVars [lambda(x [x x]) lambda(x [x x])]}} %iscombinator declare fun {IsCombinator E} {FreeVars E} == nil end {Browse {IsCombinator lambda(x x)}} {Browse {IsCombinator x}} {Browse {IsCombinator [lambda(x x) y]}} {Browse {IsCombinator [lambda(x x) x]}} {Browse {IsCombinator lambda(x [x x])}} {Browse {IsCombinator [lambda(x [x x]) lambda(x [x x])]}}