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

Lambda calculus, Type theory, Formal semantics, Program analysis

    Prev     Next     All lectures           Code

Find the maximum in a list

(define fm2$
  (lambda (X$ S$)
    (if (null? S$)
        (if (null? (take$ 1 S$))
            (let ((n (max (car X$) (car S$))))
              (cons n
                    (lambda () 
                      (fm2$ (take$ 1 (splice$ X$ (cons n (lambda() '()))))
                            (take$ 1 S$)))))))))
(define fm3$ (lambda (S$) (fm2$ (cons (car S$) (lambda () '())) S$)))
(take 20 (fm3$ (predictable-stream$ 7 67)))
 -  The code to the left is the procedure fm3$ of the previous slide except a stream is passed in place of the integer in the previous slide. This mimicks the way the problem is solved in Haskell.