User Tools

Site Tools


cs330_f2016:rackethof

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cs330_f2016:rackethof [2016/09/09 15:40]
morse
cs330_f2016:rackethof [2021/06/30 23:42] (current)
Line 4: Line 4:
   * First-class functions   * First-class functions
   * Anonymous functions   * Anonymous functions
-  * Map+  * Map (including andmap and ormap)
   * Filter   * Filter
   * Fold   * Fold
Line 18: Line 18:
 ====Deliverables:​==== ====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'':​+For this lab, you will need to reimplement the following functions from the previous lab using Racket'​s higher-order functions ''​map'' ​(including ''​andmap''​ and ''​ormap''​), ''​filter'',​ or ''​foldr''​. You may not use functions that take or return indices, such as ''​index-of''​ or ''​list-ref'':​
   * ''​convertFC''​   * ''​convertFC''​
   * ''​check-temps1''​   * ''​check-temps1''​
Line 26: Line 26:
   * ''​average''​   * ''​average''​
   * ''​eliminate-larger''​   * ''​eliminate-larger''​
 +
 +You must write these using higher-order functions rather than implementing the recursion yourself.  ​
 +As with the previous lab, you may not use ''​set!''​.
  
 In addition, you will need to implement the following function: In addition, you will need to implement the following function:
Line 35: Line 38:
 </​code>​ </​code>​
 where ''​func''​ is a two-parameter function and the result is a curried version of that two-parameter function. where ''​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.
  
 ---- ----
Line 52: Line 59:
   * Remember:   * Remember:
     * If you want to do something to each element of a list one-by-one and return a list of the results, use ''​map''​.     * If you want to do something to each element of a list one-by-one and return a list of the results, use ''​map''​.
-    * If you want to test each element of a list using a true/false predicate and get a list of those that pass the test, use ''​filter''​. ​ (If you want to see if any or all of the elements in the list pass the test, look at ''​ormap''​ and ''​andmap'',​ respectively.)+    * If you want to test each element of a list using a true/false predicate and get a list of those that pass the test, use ''​filter''​. ​ (If you want to see if any or all of the elements in the list pass the test, look at ''​ormap''​ and ''​andmap'',​ respectively. You can also see if any passed the test by checking whether the result of ''​filter''​ is an empty list.)
     * If you want to recurse through the list and at each level do something to the first thing in the list and the already-recursed-through rest of the list, use ''​foldr''​. ​ (This is quite general, and you can even use it instead of ''​map''​ or ''​filter'',​ but you might find the other two easier in many cases. ​ But some will require using ''​foldr''​.)     * If you want to recurse through the list and at each level do something to the first thing in the list and the already-recursed-through rest of the list, use ''​foldr''​. ​ (This is quite general, and you can even use it instead of ''​map''​ or ''​filter'',​ but you might find the other two easier in many cases. ​ But some will require using ''​foldr''​.)
   * 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.   * 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.
   * If your recursive implementation of some of these involved a helper function that also recursed through some list (or sublist), consider using two higher-order functions, one for each recursive function that you wrote earlier.   * If your recursive implementation of some of these involved a helper function that also recursed through some list (or sublist), consider using two higher-order functions, one for each recursive function that you wrote earlier.
cs330_f2016/rackethof.1473435650.txt.gz ยท Last modified: 2021/06/30 23:40 (external edit)