% Exam solutions declare True = fun {$ X} X end declare False = fun {$ X} fun {$ X} X end end declare If = fun {$ B} fun {$ T} fun {$E} {{B fun {$ X} T end} E} end end end {Browse {{{If True} 4} 5}} {Browse {{{If False} 4} 5}} {Browse [a b]} {Browse '|'(a '|'(b nil))} {Browse '|'(1:a 2:'|'(1:b 2:nil))} declare fun {Append L1 L2} case L1 of nil then L2 [] H|T then H|{Append T L2} end end {Browse {Append [1] [3 4]}} declare FlattenList = fun {$ L} case L of nil then nil [] H|T andthen {IsList H} then {Append {FlattenList H} {FlattenList T}} [] H|T then H|{FlattenList T} end end {Browse {FlattenList [[1] 2 [[3] 4]]}} declare fun {Minus L X} case L of nil then nil [] H|T andthen X==H then {Minus T X} [] H|T then H|{Minus T X} end end declare fun {FreeVars E} case E of lambda(F B) then {Minus {FreeVars B} F} [] [F A] then {Append {FreeVars F} {FreeVars A}} else [E] end end 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])]}}