On this page:
compose-func
flatten
flatten-foldr
bucket
tree-map
add-last-name

3.5 Higher-order Functions

You must complete this assignment by yourself.

You must submit this in an archive named "hof.zip". This archive must contain a folder named "hof". This folder must contain all the files specified below. You must attach "hof.zip" to an email whose subject is "BYU - Fall 2010 - CS 330 - hof" and whose message body contains the name of everyone on your team (each on a separate line.) You must send this email to jay@cs.byu.edu before 5pm (Provo time) on 9/14. Ensure that what you are satisfied with what you submit, because only your chronologically first submission will be graded. Ensure that you follow these instructions exactly, since submissions that do not meet these requirements (i.e. do not have the correct format) will receive no credit, despite the time and energy you put into the assignment. Please see Turn In Policy for more information.

You must submit this in a file named "hof.rkt".

Develop the following functions and datatypes in the Intermediate Student with Lambda language.

Rewrite check-temps1, check-temps, convert, average-price, convertFC, and eliminate-exp from the Lists and Trees assignment using map, filter, foldl, or foldr.

(compose-func after before)  (alpha . -> . gamma)
  after : (beta . -> . gamma)
  before : (alpha . -> . beta)
Returns the composition of before and after.

(flatten lolon)  (listof number?)
  lolon : (listof (listof number?))
Produces a list of all the numbers in the elements of lolon.

Don’t use foldr.

For example, (flatten (list (list 1 2) (list 3 4 5) (list 6))) returns (list 1 2 3 4 5 6).

(flatten-foldr lolon)  (listof number?)
  lolon : (listof (listof number?))
Produces a list of all the numbers in the elements of lolon.

Use foldr.

(bucket lon)  (listof (listof number?))
  lon : (listof number?)
Returns a list of sublists of adjacent equal numbers.

Use foldr.

For example, (bucket (list 1 1 2 2 2 3 1 1 1 2 3 3)) returns (list (list 1 1) (list 2 2 2) (list 3) (list 1 1 1) (list 2) (list 3 3)).

(tree-map f tree)  (or/c unknown? person?)
  f : (string? . -> . string?)
  tree : (or/c unknown? person?)
Returns a tree where f has been applied to every person’s name in tree.

(add-last-name tree lname)  (or/c unknown? person?)
  tree : (or/c unknown? person?)
  lname : string?
Returns a tree where lname has been appended to every person’s name in tree.

You should use tree-map and string-append.