teaching machines

CS 330 Lecture 33 – Higher-order

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

Agenda

TODO

Program This

Choose one:

Code

hof.ss

(define first car)
(define rest cdr)

(define contains
  (lambda (l item)
    (cond
      ((null? l) #f)
      ((= (first l) item) #t)
      (else (contains (rest l) item)))))

(define nth-element
  (lambda (l index)
    (cond
      ((null? l) '())
      ((= index 0) (first l))
      (else (nth-element (rest l) (- index 1))))))


(define double
  (lambda (l)
    (cond
      ((null? l) '())
      (else (cons (* 2 (first l)) (double (rest l)))))))

(define lsin
  (lambda (l)
    (cond
      ((null? l) '())
      (else (cons (sin (first l)) (lsin (rest l)))))))

(define square
  (lambda (l)
    (cond
      ((null? l) '())
      (else (cons (* (first l) (first l)) (square (rest l)))))))


(define mymap
  (lambda (f l)
    (cond
      ((null? l) '())
      (else (cons (f (first l)) (mymap f (rest l)))))))

(define differentiate
  (lambda (f)
    (cond
      ((number? f) 0)
      ((equal? 'x f) 1)
      ((equal? '+ (first f))
       (list '+ 
             (differentiate (nth-element f 1))
             (differentiate (nth-element f 2))))
      ((equal? '* (first f))
       (list '+
             (list '* (nth-element f 1) (differentiate (nth-element f 2)))
             (list '* (nth-element f 2) (differentiate (nth-element f 1)))))
      (else (display 'Idunno)))))


;(define (contains l item)
  

Haiku

Gamification.
Dress up blah with achievements.
Like matching parens.