COP 3223H meeting -*- Outline -*- * Friday problems on recursion over Lisp Lists ** a reduction ------------------------------------------ FOR YOU TO DO 1. Write a function, multList(lst) of type: LispList(int) -> int that returns the product of all the ints in the argument, lst. Examples: assert multList(Nil()) == 1 assert multList(Cons(2, Nil())) == 2 assert multList(Cons(3, Cons(2, Nil()))) == 6 assert multList(Cons(50, Cons(10, \ Cons(10, Cons(100, Nil()))))) == 500000 assert multList(Cons(5, Cons(0, Cons(7, Nil())))) == 0 ------------------------------------------ ** a filter ------------------------------------------ FOR YOU TO DO 2. Write a function, oddElems(lst) of type: LispList(int) -> LispList(int) that returns a list that has only the odd elements of lst (in their original order). Examples: assert oddElems(Nil()) == Nil() assert oddElems(Cons(1, Cons(2, Cons(3, Nil())))) \ == Cons(1, Nil()) assert oddElems(Cons(0, Cons(1, Cons(2, Cons(3, Nil()))))) \ == Cons(1, Cons(3, Nil())) assert oddElems(Cons(5, Cons(5, Cons(7, Nil())))) \ == Cons(5, Cons(5, Cons(7, Nil()))) assert oddElems(Cons(4, Cons(6, Cons(4, Nil())))) \ == Nil() ------------------------------------------ ** a map ------------------------------------------ FOR YOU TO DO 3. Write a function, cubeAll(lst) of type: LispList(int) -> LispList(int) that returns a list that has each element of lst replaced by its cube. Examples assert cubeAll(Nil()) == Nil() assert cubeAll(Cons(5, Nil())) == Cons(125, Nil()) assert cubeAll(Cons(-1, Cons(3, Cons(1, Nil()))) \ == Cons(-1, Cons(27, Cons(1, Nil()))) ------------------------------------------ ** working with 2 lists ------------------------------------------ FOR YOU TO DO 4. Write a function, append(lst1, lst2) of type: (LispList(t), LispList(t)) -> LispList(t) that returns a list that has the elements of lst1 followed by the elements of lst2. Examples: assert append(Nil(), Cons(1, Nil())) == Cons(1, Nil()) assert append(Cons(2, Nil()), Cons(-1, Nil())) \ == Cons(2, Cons(-1, Nil())) assert append(Cons(5, Cons(2, Nil()), Cons(-1, Nil()))) \ == Cons(5, Cons(2, Cons(-1, Nil()))) assert append(Cons(5, Cons(2, Nil()), Cons(2, Cons(-1, Nil())))) \ == Cons(5, Cons(2, Cons(2, Cons(-1, Nil())))) ------------------------------------------