Question: use SCHEME program .scm, language R5RS [2 marks] Create a function (repeat x n) that returns a list that contains n copies of the value

use SCHEME program .scm, language R5RS

  1. [2 marks] Create a function (repeat x n) that returns a list that contains n copies of the value x. E.g.:
     (repeat 'a 5)  (a a a a a) 
  2. [2 marks] Create a function (alternate list1 list2) that creates a list by alternating elements from the two given input lists. E.g.:
     (alternate '(0 0 0 0) '(1 1 1 1 1 1))  (0 1 0 1 0 1 0 1 1 1) 
  3. [2 marks] Create a procedure (count x L) that returns the number of instances of the value x in the list L. E.g.:
     (count 3 '(1 4 3 6 2 3 3 1 4 3 5 7))  4 (count 'b '(4 b a 3 2 c b 1 b 2 d a))  3 
  4. [4 marks] Create a procedure (mode L) that returns the most common value in the list L. Hint: this question is asking that you find the item with the largest count. In the case of a tie return the value closest to the front of the list (ie the first one encountered). E.g.,
     (mode '(a b a c a d d a b c a b))  a (mode '(2 b a 3 2 c b 1 b 2 d a))  2 
  5. [5 marks] Create a procedure (decreasing L) that returns a list of all of the consecutive decreasing subseqeuences in the input list. E.g.,
     (decreasing '(3 6 8 9 7 4 8 6 3))  ((9 7 4) (7 4) (8 6 3) (6 3)) (decreasing '(7 6 5 4 8 5 2 5 1 5 2 1))  ((7 6 5 4)(6 5 4)(5 4)(8 5 2)(5 2)(5 1)(5 2 1)(2 1)) (decreasing '(1 2 3 4 5))  ()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!