Computer Science 3675
Fall 2011
Practice Questions for Quiz 4

  1. Scheme is a typeless language. What does that mean? Can type errors ever occur?

    Answer

  2. What is the value of Scheme expression (car (cdr (cons 'horse (cons 'zebra '()))))?

    Answer

  3. What is the value of Scheme expression (cons 'salamander (list 'frog 'toad))

    Answer

  4. Write a Scheme function called prefix so that (prefix x y) returns true if list x is a prefix of list y (and false if not). It is not necessary for x to be a proper prefix of y. Every list is a prefix of itself, and the empty list is a prefix of every list. Be careful to use Scheme syntax correctly.

    Answer

  5. Write a Scheme function called descending so that (descending L) is true for a list of numbers L if L is in descending order. (The Scheme function < does a less-than test, and > does a greater-than test.) List (a b c d) is in descending order if a > b > c > d. The empty list is in descending order by definition, as is a singleton list. Be careful to use Scheme syntax correctly.

    Answer

  6. Write a Scheme function called drop so that (drop n L) returns the result of removing the first n members from list L. If L has fewer than n members, then (drop n L) should return the empty list. For example, (drop 2 '(4 8 3 5 7)) = (3 5 7) and (drop 3 '(5 2)) = (). Be careful to use Scheme syntax correctly.

    Answer

  7. Write the filter function in Scheme. That is, write a filter function so that (filter f L) returns a list of all members x of list L such that (f x) is not #f. Do not try to make it lazy. Be careful to use Scheme syntax correctly.

    Answer