lookup(Variable,[bind(Variable,Value)|_],Value). lookup(VarX,[bind(VarY,_)|Rest],Value) :- VarX \= VarY, lookup(VarX,Rest,Value). val3(plus(X,Y),Context,Value) :- val3(X,Context,XValue), val3(Y,Context,YValue), Value is XValue + YValue. val3(times(X,Y),Context,Value) :- val3(X,Context,XValue), val3(Y,Context,YValue), Value is XValue * YValue. val3(const(X),_,X). val3(var(X),Context,Value) :- lookup(X,Context,Value). val3(let(X,Exp1,Exp2),Context,Value2) :- val3(Exp1,Context,Value1), val3(Exp2,[bind(X,Value1)|Context],Value2). val3(fn(Formal,Body),Context,fval(Formal,Body,Context)). val3(apply(Function,Actual),Context,Value) :- val3(Function,Context,fval(Formal,Body,Nesting)), val3(Actual,Context,ParamValue), val3(Body,[bind(Formal,ParamValue)|Nesting],Value).