20-CS-4003-001 Organization of Programming Languages Fall 2017
Lambda

Lambda calculus, Type theory, Formal semantics, Program analysis

    Prev     Next     All lectures           Code

Lambda - Y Combinator

(define fact-maker
  (lambda (procedure)
    (lambda (n)
      (if (zero? n)
          1
          (* n (procedure (- n 1)))))))
 -  Step 1. The first idea is simply to pass "fact" in as an argument in much the same way that we did for
   (define op-maker (lambda (op) (lambda (x y) (op x y))))

The first attempt is shown to the left where we try to pass "fact-maker" in through "procedure". Thus, what we would like to do is invoke

   (fact-maker fact-maker)
to produce our nameless (well, almost nameless) factorial procedure. This would allow us to write, for example
  prompt> ((fact-maker fact-maker) 5)
  120
But, this doesn't work because "fact-maker" is a procedure which takes as input one argument that is a procedure but "procedure", which is supposed to be identical to "fact", requires a numeric argument.