20-CS-4003-001 | Organization of Programming Languages | Fall 2018 |
---|---|---|
Lambda |
Lambda - Hamming Sequences
(define hamming$ (lambda (primes) (if (null? primes) '() (cons (car primes) (lambda () (merge$ (times$ (car primes) (hamming$ primes)) (hamming$ (cdr primes)))))))) prompt> (take 16 (hamming$ '(3 5 11))) ;Value 38: (3 5 9 11 15 25 27 33 45 55 75 81 99 121 125 135) |
- | Procedure hamming$ finds Hamming sequences using the delay-force paradigm on earlier slides. An example is shown to the left. Observe that since primes is not a stream, no occurence of ((cdr ...)) is in the procedure. But since hamming$ produces a stream, the (lambda () ...) must surround the (merge$ ...). | ||