teaching machines

CS 330 Lecture 32 – Scheme, Part II

April 23, 2012 by . Filed under cs330, lectures, spring 2012.

Agenda

TODO

Reverse Engineering

Program This

Choose one or both:

Code

clog.ss

(define clog
  (lambda (n base)
    (cond
      ((<= n 1) 0)
      (else (+ 1 (clog (/ n base) base))))))

stuff.scm

(define calc-tax
  (lambda (price) (* 1.055 price)))

(calc-tax 3.69)
;; ((lambda (price) (* 1.055 price)) 3.69)

(define !
  (lambda (n) 
    (cond
      ((= n 0) 1)
      (else (* n (! (- n 1)))))))

(define first car)
(define rest cdr)

(define merge
  (lambda (a b)
    (cond
      ((null? a) b)
      ((null? b) a)

      ; there's something in both a and b

      ; a wins
      ((> (first b) (first a)) (cons (first a) (merge (rest a) b)))

      ; b wins or tie
      (else (cons (first b) (merge a (rest b)))))))

Haiku

Scheme got rid of VOID.
VOID checked out library books.
Never returned them.