CS 330 Lecture 32 – Scheme, Part II
April 23, 2012 by Chris Johnson. Filed under
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
cs330, lectures, spring 2012.
Agenda
- why functional?
- why not functional?
- reverse engineering
- finish merge
- program this
- double, square, cosine
- higher-order functions
- map and filter
- variable-length argument lists
- symbolic differentiation
TODO
Reverse Engineering
Program This
Choose one or both:
- Write contains, which takes two arguments: a list and an atom. Return true if the list contains the atom.
- Write nth-element, which returns the the nth-element (starting at 0) of the list.
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.