University of California, Berkeley
EECS Department - Computer Science Division

CS3 Lecture 13 : Higher-Order Functions (cont'd)


Overview of today's lecture


Review


Higher-Order Functions (cont'd)

Defining functions as one another

: (define (plus x y) (+ x y))
plus
: (+ 1 2)
3

: (plus 1 2)
3

: (+ 1 2 3)
6

: (plus 1 2 3)
*** ERROR -- Wrong number of arguments passed to procedure
(plus 1 2 3)
: (define plus +) ;; Now plus and + are identical!

: (+ 1 2 3)
6

: (plus 1 2 3)
6

Temporary variables : another way to do it

: (+ (hour-long-function 3) (/ (hour-long-function 3) 2))
12
: (let ((hlf (hour-long-function 3))
     (+ hlf (/ hlf 2)))
12
: (define (hlf-helper hlf)
    (+ hlf (/ hlf 2)))
hlf-helper

: (hlf-helper (hour-long-function 3))
12


Summary

Next Time

Puzzle : Infinite Baseball

Game : Tac Tix [BerlekampConwayGuy82]

References


WWW Maven: Dan Garcia (ddgarcia@cs.berkeley.edu) Send me feedback

Dan Garcia Berkeley Computer Science