CS计算机代考程序代写 scheme 1. Write a recursive Scheme function negatives that take a list as its argument returns the count of negative numbers (less than 0) in that list. Note that the built-in predicate number? returns #t for any number. This implementation must NOT be tail-recursive.

1. Write a recursive Scheme function negatives that take a list as its argument returns the count of negative numbers (less than 0) in that list. Note that the built-in predicate number? returns #t for any number. This implementation must NOT be tail-recursive.
Here are some examples:
(negatives ‘(hello 5 5 -3 0 #t -200)) -> 2
(negatives ‘(1 2 3)) -> 0
(negatives ‘()) -> 0

2. Write a Scheme function drop-two that takes in a list xs as its arguments and returns a new list that contains all the elements of xs, in order, except the last two.
Here are some examples:
(drop-two ‘(1 2 3 4 5)) -> (1 2 3)
(drop-two ‘(1 2 3 4 5 6)) -> (1 2 3 4)
(drop-two ‘(hello world)) ->()
(drop-two ‘()) -> ()
(drop-two ‘(1)) -> ()

3. Write a Scheme function insert that takes in an element e and a list xs as its arguments and returns a new list that contains all the elements of xs with e inserted between consecutive elements of the original list. If the list xs is empty, the function returns an empty list.
Here are some examples:
(insert 0 ‘(1 2 3 4 5)) -> (1 0 2 0 3 0 4 0 5)
(insert ‘beautiful ‘(hello world)) -> (hello beautiful world)
(insert 0 ‘(1)) -> (1)
(insert 0 ‘()) -> ()

4. Write a Scheme function addlists that takes two lists of numbers, and returns a new list. The elements of the new list are obtained by adding the corresponding elements of the two lists. If one of the lists is longer than the other, the extra elements of the longer list are included at the end of the new list.
Here are some examples:
(addlists ‘(1 2 3) ‘(100 200 300 400 500)) -> (101 202 303 400 500)
(addlists ‘(1 2 3 4 5) ‘(100 200)) -> (101 202 3 4 5)
(addlists ‘() ‘(4 5 6)) -> (4 5 6)
(addlists ‘(1 2 3) ‘()) -> (1 2 3)
(addlists ‘() ‘()) -> ()

5. Write a Scheme function repeat that takes a list as its argument. and returns a new list where each element of the original list appears twice, in order.
Here are some examples:
(repeat ‘(1 2 3)) -> (1 1 2 2 3 3)
(repeat ‘(go spartans))->(go go spartans spartans)
(repeat ‘())->()
(repeat ‘(1 1))->(1 1 1 1)

6. Write a Scheme predicate isdouble? that takes a list as its argument . The function returns #t if each element in the list appears twice in a row. The function returns #f otherwise.
Here are some examples:
(isdouble? ‘(1 1 2 2 3 3)) -> #t
(isdouble? ‘(5 5 5 5)) -> #t
(isdouble? ‘(1 1 2 3 3)) -> #f
(isdouble? ‘()) -> #t
(isdouble? ‘(1)) -> #f

7. Write a Scheme function take-while that takes a predicate (a function) and a list as arguments. The function returns a new list that contains the first few elements of the input list that meet the criteria specified by the predicate. The first element that does not meet the criteria and all subsequent elements are excluded. Here are some examples:
(take-while (lambda (x) ( > x 3 )) ‘(9 4 2 3 7 8 6)) -> (9 4)
(take-while (lambda (x) ( > x 5 )) ‘(4 2 3 7 8 6)) -> ()
(take-while (lambda (x) ( = x 5 )) ‘()) -> ()

8. Write a tail recursive function positives that takes a list as its argument and returns the count of positive numbers (including 0) in that list. Note that the built-in predicate number? returns #t for any number. For full credit, your implementation must be tail recursive and it must not use any higher-order functions.
Here are some examples:
(positives ‘(hello 5 5 -3 0 #t -200)) -> 3
(positives ‘(-3 #t hello)) -> 0
(positives ‘()) -> 0