Suppose that we say:

Cons lst = list( list("a", "b"), list("c", "d"));
boolean test = ( first(lst) ==
                 first(reverse(reverse(lst))) );

What is the value of test?

  • A: true
  • B: false
  • C: null
  • D: error
  • E: could be true or false

    Answer: A

    reverse operates at the top level of a list only, i.e. it makes a backward copy of the input list, but does not modify the objects that the list contains. reverse(reverse(lst)) is a backwards copy of a backwards copy, so it is a copy of the original in the original order. The first item of the copy is exactly the same item as in the original, so the pointers are equal in numeric value and are ==.

    Contents    Page-10    Prev    Next    Page+10    Index