2014-10-08 LAB

posted Oct 8, 2014, 5:12 AM by Samuel Konstantinovich   [ updated Oct 8, 2014, 5:12 AM ]
Lab Basic Lists: 
(Write your functions in lambda notation)

1. Write a function (second x) that accepts a list as a parameter, and returns the 2nd element. 
1b. Modify your function return the 2nd element when there are at least 2 elements, or return false if there aren't enough elements.
e.g.
(second '( a b c) ) -> b
(second '( 1 ) ) -> #f

2. Write a function (third x) that accepts a list as a parameter, and returns the 3rd element. 
2b. Modify your function return the 3rd element when there are at least 3 elements, or return false if there aren't enough elements.
(third '( a b c) ) -> c
(third '( a b ) ) -> #f


3. Make a function (sumList3 x) that accepts a list of 3 integers, and returns the sum of the integers. It returns 0 when the list has a different number of elements. You can assume the elements are integers. 
(sumList3 '(1 9 2) ) -> 12
(sumList3 '(12 13 14 15) ) -> 0
Comments