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
  ((lambda (procedure)
     ((lambda (func-arg)
        (lambda (n)
          (if (zero? n)
              1
              (* n (func-arg (- n 1))))))
      (lambda (arg) ((procedure procedure) arg))))
   (lambda (procedure)
     ((lambda (func-arg)
        (lambda (n)
          (if (zero? n)
              1
              (* n (func-arg (- n 1))))))
      (lambda (arg) ((procedure procedure) arg))))))
 -  Step 4. - Now we are ready to take the result of Step 3 and apply it to the result of Step 2. Writing out the whole thing, we get the code to the left. You will probably want to study this carefully. Notice the double left parens in front of ((lambda (func-arg)... This is because we are writing
   ...
   ((lambda (func-arg) <body-using-func-arg>) (lambda (arg) ...))
which has the same form as
  ((lambda (arg) ((procedure procedure) arg)) (- n 1))
but is different in that a procedure is passed as an "arg" instead of an integer.