Lab 3
1 Actual Brain Exercise

Lab 3

1 Actual Brain Exercise

  1. Develop the function rev-str-app, that accepts a list of strings and returns a single string combining the input strings in reverse order. Use string-append to join strings. So, calling the function with the list containing the strings "ball", "juice", and "frog" would produce the string "frogjuiceball". Follow the design recipe, including types, purpose statement, and test cases

  2. Develop a representation for fruits; A fruit can be either a lemon, a melon, or a nomel. Each one has a single field that is a number [*]. Define these using a define-type.

  3. Develop the function onlyLemons, that consumes a list of fruits and returns a list containing only the lemons.

  4. Develop the function onlyMelons, that consumes a list of fruits and returns a list containing only the melons.

  5. Abstract over the two of these to obtain the function onlyThese, that consumes a list of fruits and a particular fruit predicate f (e.g., lemon?)and returns a list containing only those elements of the list that satisfy f. (Note: you’re passing the function lemon? here. If this doesn’t make sense, ask for help!

  6. Develop the my-append function that consumes two lists and returns the result of appending the second one to the first. So, if called with the list [a,b,c] and the list [d,e,f], it would return [a,b,c,d,e,f].

  7. Develop the my-take function that consumes a list and a number n and returns the first n elements of the list. If the list contains fewer than n elements, it returns the entire list.

[*] I don’t care what the field is called. Actually, I don’t care whether they have fields or not, but experience shows that constructors with no arguments along with higher-order procedures confuse the heck out of students just getting used to Racket. If this doesn’t make sense to you, just take my advice and make up a field for each one.