Write a function last
that returns
the last element of a list.
> last [2, 4, 6, 8] 8
Write a function secondLast
that
returns the second-to-last element of a list.
> secondLast [2, 4, 6, 8] 6
Write a function kth
that returns the
kth element of a list, where elements are numbered starting from 0.
(Do not use the built-in operator !!
, which does the
same thing.)
Implement the built-in function zip
that converts two lists into a list of pairs:
> zip [10, 12, 14] [21, 23, 25, 27] [(10,21),(12,23),(14,25)]
Stop zipping when you reach the end of either list.
Write a function dedup
that
eliminates consecutive duplicate
elements in a list:
> dedup [2, 4, 4, 4, 6, 6, 8, 4] [2, 4, 6, 8, 4]
Which of these functions is equivalent to the
built-in operator ||
?
or _ True = True
or True _ =
True
or _ _ = False
or True False = True
or True True
= True
or False True = True
or False False = False
or a b = b || a
Construct a list ints
of integers
from 1 to ∞. Do not use the built-in range operator (i.e. [1
.. ]
).
Implelement the built-in function cycle
that takes a list L and returns an infinite list consisting of L
repeated over and over:
> take 10 (cycle "abc") "abcabcabca"
Write a function that determines whether an integer is prime.
Construct an infinite list containing all prime numbers.
Write a function that breaks a string into a list of words.