20-CS-4003-001 Organization of Programming Languages Fall 2018

Lambda calculus, Type theory, Formal semantics, Program analysis

    Prev     Next     All lectures           Code

Lambda - Y Combinator

(define Y
  (lambda (X)
    ((lambda (procedure)
       (X (lambda (arg) ((procedure procedure) arg))))
     (lambda (procedure)
       (X (lambda (arg) ((procedure procedure) arg)))))))

(define F*
  (lambda (func-arg)
    (lambda (n)
      (if (zero? n)
          (* n (func-arg (- n 1)))))))
 -  Step 6. We can write "fact" in terms of the Y-combinator as follows:
   prompt> (define fact (Y F*))
Try (fact 5) to check the result. For that matter, try
   prompt> ((Y F*) 5).
But Y is general and F* is specific to factorial but with no name! If we wrote the whole thing out it would look like the code on the left.