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 Y (lambda (X) ((lambda (procedure) (X (lambda (arg) ((procedure procedure) arg)))) (lambda (procedure) (X (lambda (arg) ((procedure procedure) arg))))))) (define findmax (lambda (fdx) (lambda (l) (if (null? l) 'no-list (if (null? (cdr l)) (car l) (max (car l) (fdx (cdr l)))))))) (define Y-multi (lambda (X) ((lambda (procedure) (X (lambda arg (apply (procedure procedure) arg)))) (lambda (procedure) (X (lambda arg (apply (procedure procedure) arg))))))) (define member-of (lambda (f) (lambda (lst a) (if (null? lst) '() (if (eq? (car lst) a) #t (f (cdr lst) a)))))) ``` - Here is a second example: find the maximum number in a given list. Try it like this: ``` prompt> ((Y findmax) '(7 3 2 9 1 2 3)) ;Value: 9 ``` The procedure Y-multi is a slight modification to Y that supports any F* of any number of arguments. Try it on member-of.