Learn how to use first-class and higher-order functions:
You will again use DrRacket, which you should have downloaded and installed for the previous labs.
For this lab, you will need to reimplement the following functions from the previous lab using Racket's higher-order functions
foldr. You may not use functions that take or return indices, such as
You must write these using higher-order functions rather than implementing the recursion yourself.
As with the previous lab, you may not use
In addition, you will need to implement the following function:
(define (curry2 func) ...)
func is a two-parameter function and the result is a curried version of that two-parameter function.
You may not use any built-in curry functions to implement this.
Hint: You don't need to know what the function passed in actually does. All you need to know is that it requires two parameters, and once you have those parameters you use the function.
You again do not need to bulletproof the code to enforce proper inputs. Your code only needs to return correct values given correct inputs.
You may also use other higher-order functions such as
ormap, etc., but these are not required These short-circuit the map-and-fold process rather than performing all of the mapping and then folding the results. You will find that trying to pass the
or operators to higher-order functions won't work because they are special forms and not just ordinary functions.
filter. (If you want to see if any or all of the elements in the list pass the test, look at
andmap, respectively. You can also see if any passed the test by checking whether the result of
filteris an empty list.)
foldr. (This is quite general, and you can even use it instead of
filter, but you might find the other two easier in many cases. But some will require using
foldr, the trick is to figure out what to use for the folding operator. Remember that when called it will receive two parameters: the first thing in the list and the already folded rest of the list. (There's a bit of a leap of faith here, just like recursion.) Then think about what it is you want to do with those two pieces of data. Be careful with your selection of the base for the folding as well and use what you would return for the empty list.