User Tools

Site Tools


cs330_f2016:rackethof

This is an old revision of the document!


Objective:

Learn how to use first-class and higher-order functions:

  • First-class functions
  • Anonymous functions
  • Map
  • Filter
  • Fold

Preparation:

You will again use DrRacket, which you should have downloaded and installed for the previous labs.


Deliverables:

For this lab, you will need to reimplement the following functions from the previous lab using Racket's higher-order functions map, filter, or foldr:

  • convertFC
  • check-temps1
  • check-temps
  • convert
  • duple
  • average
  • eliminate-larger

In addition, you will need to implement the following function:

  • curry2

curry2

(define (curry2 func) ...)

where func is a two-parameter function and the result is a curried version of that two-parameter function.


Notes:

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 andmap, 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 and and or operators to higher-order functions won't work because they are special forms and not just ordinary functions.


Hints:

* Look at the pattern or recursion used for each problem in the previous assignment and then choose a suitable higher-order function for that.

* When 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.

cs330_f2016/rackethof.1473201816.txt.gz · Last modified: 2021/06/30 23:40 (external edit)