Ch1 HW2

Warmups

  1. GREET-IZE: String -> (String->String). Take in a greeting. Return a function that takes in a name and outputs the string “greeting, name”.
(define-test TEST-GREET-IZE 
  "Verify you understand function-returning functions."
  (assert-equal "Hello, Doc" (funcall (greet-ize "Hello") "Doc"))
  (assert-equal "Goodbye, World" (funcall (greet-ize "Goodbye") "World")))
  1. WIPE-NESTED: List -> List. Change every non-list any nested list of the input to ‘BLACK.
(define-test TEST-WIPE
  "Make sure the structure of the list is retained when wiping."
  (assert-equal '(BLACK BLACK BLACK) (wipe-nested '(orange blue green)))
  (assert-equal '(BLACK (BLACK BLACK BLACK) BLACK ((BLACK)))
                (wipe-nested '(R (R G B) G ((B))))))

Homework

This is practice programming from Chapter 1.

  1. Function DUBL: doubles its input.
  2. Write a single test for DUBL.
  3. Function DUBLR: doubles every input in a list.
  4. Colorizer: turns integers into color symbols: 1 -> 'RED', 2 -> 'WHITE, 10 -> 'BLUE, any other becomes 'NONE.
  5. Function N-NER: takes in a number and a list. Adds the number to every element in the list (returning the new list).
  6. Function MY-MAKE-SEQ: inputs are three numbers (a,b,c), output is a function that takes in a number x and puts out the list (x+a, x+b, x+c).
  7. Write two tests for MY-MAKE-SEQ.