puzzle for student presentation
implement an abstract data type for finite functions
- (mk-fun a b) creates a function that maps a to b
- (+fun f g) gives the function that is like g on g’s domain, and like f elsewhere
- (app-fun f x) gives the result of “applying” f to x(if x is not mapped by f, just return x itself)
example
- (define phonebook (+fun (mk-fun ‘daniel 2471) (mk-fun ‘barb 2130) (mk-fun ‘steve 1234)))
- (app-fun phonebook ‘daniel) –> 2471
hint
- no cons needed!
- solution of 5 lines possible