CS 356 Programming Languages Spring 2019 

Homework Assignment 1

  1. (10 points) Write a Racket program that returns the count of the number of times an item appears in a given list. Provide several test cases to demonstrate the correctness of your code.
    (appears 3 '(4 3 2 1 2 3 4)) produces 2.
  2. (10 points) Write a Racket program that returns the a list that is reversal of the items in a given list. Don't use the reverse function. Provide several test cases to demonstrate the correctness of your code.
    (myReverse '(4 3 2 1)) produces '(1 2 3 4).
  3. (10 points) Write a Racket program that returns the a position of a given item in given list of items (0 through the length of the list-1) or -1 if the item is not found. Provide several test cases to demonstrate the correctness of your code.
    (positionOf 7 '(4 3 2 1)) produces -1.
  4. (10 points) Write a Racket program that returns the a list that is a deep reversal of the items in a given list. That is, reverse all sublists (and sublists of sublists, etc) of the reversed list. Don't use the reverse function. Provide several test cases to demonstrate the correctness of your code.
    (DeepReverse '(4 3 '("a" "b" "c") 2 1)) produces '(1 2 '("c" "b" "a") 3 4).
  5. (10 points) Write a Racket program that returns flattened list of items of a given list. Provide several test cases to demonstrate the correctness of your code.
    (Flatten '(1 2 '("a" "b" "c") 3 4)) produces '(1 2 "a" "b" "c" 3 4).


Copyright © 2019, David A. Reimann. All rights reserved.