Here's a list of Scheme list-processing functions. If you don't know what they do, either look them up in the Scheme crib-sheet, or try them out and experiment with them.
Let L and L1, L2, etc. be lists below, and AL be an atom-or-list
(CAR L) (CDR L) (LIST ...) (APPEND L1 L2 ...) (CONS AL L) (LIST? AL) (NULL? L) (LENGTH L) (REVERSE L) (EQUAL? AL1 AL2)
1. Create 3 versions of the function called Rev3(L) which will be given a single list of 3 elements, and will return a list with those elements in reverse order. By chance, you may have noticed the function REVERSE in the list of functions above. Of course, you MAY NOT use it.
(define blark '(will I go)) (REV3 blark) ;-> (go I will) (REV3 '((a b) c d)) ;-> (d c (a b))
1a) First version, called Rev3-List, must
use the LIST
function somewhere in the definition, and any other functions you
need.
1b) Second version, called Rev3-Append, must use APPEND,
etc.
1c) Third version, called Rev3-Cons, must use CONS, etc.
2a) Create the function IsInL2?(L,a) which will be given, as its first argument, a list L of 2 atoms, and as its second argument, an atom a, and will return #t if a is the same as the first or second elements of L (or both), otherwise #f.
(IsInL2? '(fred george) 'fred) ;-> #t (IsInL2? '(evil Voldy) 'goodness) ;-> #f
2b) Create the function IsInL3?(L,a), which will do the same thing, except this time, L has 3 elements.
3) Create the function Add3(L), which will be given a list of 3 numbers, and will return their sum:
(define duh '(3 18 -5)) (Add3 duh) ;-> 16
4) Create the function Last2Equal?(L) which will be given a list of any number of elements, and will return #t if the last 2 elements in the list are equal, and #f if they're different, and also #f if the list contains less than 2 elements:
(Last2Equal? '(2 18 fred fred)) ;-> #t (Last2Equal? '(2 18 fred fred 7)) ;-> #f (Last2Equal? '()) ;-> #f
5) Create the function MakePalindrome(L) which will create a palindrome from the non-empty list that it's given. If you don't know what a palindrome is, look it up. Also, look carefully at the examples below:
(MakePalindrome '(a b c)) ;-> (a b c b a) (MakePalindrome '(fred)) ;-> (fred) (MakePalindrome '(1 2 3 4 (whatever)) ;-> (1 2 3 4 (whatever) 4 3 2 1)