A few pages ago, we wrote the blocks
The functionality of these blocks (and, probably, your implementations of them) bear a striking resemblance to one another.
Computer scientists love generalization, so let's make a block that can accomplish the duties of both
of the above blocks. Since the main difference between the two is what predicate they use, we'll add that as in input.
Hint: when writing the block below, call
will be quite useful.
Once you've written this block, try running it like this:
Does the output match the "list all" blocks from earlier?
Now, imagine you're given a new predicate, such as:
and want to write the block
Wait! Doesn't this sound pretty familiar? This problem can be easily solved using the general block we just created (you don't actually have to solve this one)
The beauty of abstraction: build once, use over and over again! When we wrote the list all numbers with property
block, we didn't know
that we'd ever want to list even numbers! But since we generalized properly, we were able to use the block to solve a future problem.