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 F*
  (lambda (func-arg)
    (lambda (n)
      (if (zero? n)
          1
          (* n (func-arg (- n 1)))))))


(define fact
  ((lambda (procedure)
     (F* (lambda (arg) ((procedure procedure) arg))))
   (lambda (procedure)
     (F* (lambda (arg) ((procedure procedure) arg))))))
 -  The two expressions beginning with (lambda (func-arg) ...) are exactly the pieces of code that correspond to the factorial code and they are in exactly the right form. So we can get them out of the definition of fact, resulting in the code shown to the left. This is significant because we can now use any procedure in place of F* to change functionality to whatever we want. The only problem is that, as written, we still need to name F*. This is easily remedied in the next step.