Lists and List Comprehensions
- Suppose you have two lists of integers,
left
andright
. You want to determine whether those lists are equal, that is, whether they have all the same members in the same order. How would you implement such a list comparison?
Here are some hints.
If
left
is[]
, what doesright
have to be forleft
andright
to be equal? (Come on, it's not too hard.)Suppose on the other hand that
left
has headx
and tailxs
.- If
right
is then[]
, areleft
andright
equal? - If
right
isn't[]
, and its head isn't equal tox
, areleft
andright
equal? - If
right
isn't[]
, and its head is equal tox
, what else has to be the case forleft
andright
to be equal?
- If
Can you now write a recursive definition of the
list_equal
function? What's your base case?