1. Go over lambda calculus problem Rightmost [(Lf.Lg.f (g 1))(Lx.x+4)](Ly.3-y) => [Lg.(Lx.x+4)(g 1)](Ly.3-y) OK BUT => (Lf.f ((Ly.3-y) 1)(Lx.x+4) NOT OK Rule of Beta-reduction is that you can only substitute the applied argument into the 1st lambda variable, so that is Lf 2. Haskell demo 3. Exceptions and where they're caught try{ function f(y) { throw "exn"}; function g(h){ try {h(1)} catch(e){return 2} }; try { g(f) } catch(e){4}; } catch(e){6}; establish the catch clause right before try's activation record is created what if I move throw "exn" to under g(f) 4. Continuations The continuation of an expression is the remaining work to be done after evaluating the expression Continuation of e is a function normally applied to e 4^2 = 1+3+5+7 function dumb_nth_square(n) { if (n==1) return 1; else { n+n-1+dumb_nth_square(n-1); } } say we're doing d_n_s(5). What's continuation of d_n_s(5)? Identity function Lw.w What's continuation of d_n_s(4) if we are calculating d_n_s(5) Lx.(x+9) Continuation of d_n_s(3) here Ly.(Lx.(x+9))(y+7) generalize now how do we write this in a continuation style? function dumb_nth_square(n) { function f(n, g) { if(n==1) {return g(1);} else return f(n-1, function(x){return g(x)+n+n-1;} (in lambda => else f(n-1, Lx.((g x)+n+n+1)) } return f(n, function(x){return x;} } Trying to write out d_n_s(3) d_n_s(3) => f(3, Lx.x) n==3 => f(2, Ly.((Lx.x) y)+5) n==2 => f(1, Lz.(Ly.((Lx.x) y)+5)) z)+3) n==1 => (Lz.(Ly.((Lx.x) y)+5)) z)+3) 1 = (Ly.((Lx.x) y)+5)) 1)+3 = ((Lx.x) 1)+5+3 = 1+5+3 = 9