%foldr declare fun {FoldR F U L} case L of nil then U [] H|T then {F H {FoldR F U T}} end end {Browse {FoldR Number.'+' 0 [1 2 3 4]}} {Browse {FoldR Number.'*' 1 [1 2 3 4]}} % append as foldr aplication declare fun {Append L1 L2} {FoldR fun {$ H T} H|T end L2 L1} end {Browse {Append [1 2] [3 4]}} % filter as foldr application declare fun {Filter P L} {FoldR fun {$ H T} if {P H} then H|T else T end end nil L} end {Browse {Filter fun {$ A} A < 3 end [1 2 3 4]}} % remove as filter application declare fun {Remove X L} {Filter fun {$ V} V \= X end L} end {Browse {Remove 2 [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 {Remove V {FreeVars E}} [] 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])]}} {Browse {IsCombinator [lambda(x x)]}}