% $Id$ declare % ::= varref() % | app( ) % | lambda( ) % % FV: }: > fun {FV Exp} case Exp of varref(Name) then Name|nil [] app(E1 E2) then {Union {FV E1} {FV E2}} [] lambda(Name Body) then {Remove {FV Body} Name} end end % BV: }: > fun {BV Exp} case Exp of varref(Name) then nil [] app(E1 E2) then {Union {BV E1} {BV E2}} [] lambda(Name Body) then local BVs = {BV Body} in if {Member Name {FV Body}} then {Insert BVs Name} else BVs end end end end % Insert: }: > fun {Insert Ls Name} if {Member Name Ls} then Ls else Name|Ls end end % Union: }: > fun {Union Ls1 Ls2} case Ls1 of H|T then if {Member H Ls2} then {Union T Ls2} else H|{Union T Ls2} end else Ls2 end end % Remove: }: > fun {Remove Ls Name} case Ls of H|T then if H == Name then {Remove T Name} else H|{Remove T Name} end else nil end end