University of California, Berkeley
EECS Department - Computer Science Division
CS3 Lecture 16 : The Power of Lambda
Overview of today's lecture
Review
- Lambda expressions are a way of creating nameless functions.
- We use them mostly with Higher Order functions, but also
other places when appropriates
Review and More Lambda Help
Overview
- Dan reviews Lambdas and Higher-Order Functions and anything
else people want to see
Questions
- Write count-if-not which, like count-if,
returns the number of words that don't satisfy the predicate
pred?
- Write a function, make-xnor, that takes no arguments
and returns a function that takes two booleans and returns true
if and only if the booleans are both true or both false
- Write a function, make-xor, that returns a procedure
that takes two arguments and returns true when the procedure
make-xnor returns false and vice versa.
- Write add-sents which adds sentences. That is, given
two sentences of equal length, return the sum of each corresponding
pair of words. (add-sents '(1 20 3) '(10 7 50)) ==> (11
27 53)
Summary
- We reviewed some of the more difficult concepts today.
Next Time
- We will take a midterm together during class!
Puzzle : Miracle-Fold Maps
- Divide a sheet of paper into eight parts.
- Number them on one side as in the diagram.
- The problem is to fold the paper (along the lines) to form
a packet (like a folded map) with No. 1 face up on top, followed
by the other numbers in order.
Game : Toads and Frogs (Winning Ways p.
14)
- Left has trained a number of Toads and Right a number of
Frogs to play the following game.
- Each player may persuade one of his creatures either to move
one square or to jump over an opposing creature, onto an empty
square.
- Toads move only Eastward, Frogs only to the West (toads
to, frogs, fro).
- The game is to be played according to the normal play rule
that a player unable to move loses.
- In general, you can set up an arbitrary amount of frogs and
toads positioned arbitrarily on, say, a chessboard, and play.
- Who wins the game below? Play it several times to find out.
Toad | | Frog | |
| Toad | | Frog |
Toad | Frog | | |
| Toad | Frog | |
| Toad | | Frog |
WWW Maven: Dan
Garcia (ddgarcia@cs.berkeley.edu)
Send me feedback