Posted: November 23rd, 2015

Programming a few procedures in scheme

Programming a few procedures in scheme

Using Scheme:
1.    Create a procedure called (combine-four lst1 lst2 lst3 lst4) that combines 4 lists into one list, in order of the given input lists.
Test case: (combine-four ‘(1 2) ‘(3 4) ‘(5 6) ‘(7 8 9)) should give ‘(1 2 3 4 5 6 7 8 9)

2.    Create a procedure that returns the last n items in the list lst.
3.1 Use a named procedure called (last-n lst n) to implement task.
Test case: (last-n ‘(1 6 3 4 5) 2) should give ‘(4 5)
3.2 Use an unnamed procedure ((lambda (lst n) (. . .) ‘(1 6 3 4 5) 2) to implement task, where ‘(1 6 3 4 5) 2 are the arguments.
The unnamed procedure should give ‘(4 5)

3.    Create a procedure called (first-n lst) that returns the first n items in the list lst. You must read in the value for n. You must not change the order of the list elements.
Test case with read-in input 3: (first-n ‘(1 5 3 4 5)) should give ‘(1 5 3)

4.    Create a procedure called (shuffle lst1 lst2) that returns a shuffle of two lists. Shuffle the lists by alternating elements between the two lists. You can assume that both lists have the same length.
Test case: (shuffle ‘(1 2 3) ‘(a b c)) should give ‘(1 a 2 b 3 c).

5.    Create a procedure called (shufflePairs one two) that returns a shuffle of two lists in pairs. You can assume that both lists have the same length.
Test case: (shufflePairs  ‘(1 2 3) ‘(a b c)) is ‘((1 . a) (2 . b) (3 . c)).

6.    Create a procedure called (addSquare lst), where lst is a list of numbers. The procedure will calculate the square of each number in the list, add all the squared values, and then return the sum. If lst is empty, this procedure must return “empty list”. If lst is not empty, the procedure should call another procedure called (addNonEmptyList lst) that returns the sum of square values of all elements in the lst. If lst is empty, (addNonEmptyList lst) procedure should return 0 (the value a the stopping condition). For example, (addSquare ‘(1 2 3)) should return the sum of 12 + 22 + 32
Note, you could use map function, but you do not have to use it.
Test cases:
(addSquare ‘())
(addNonEmptyList ‘())
(addNonEmptyList ‘(1 2 3))
(addNonEmptyList ‘(1 4 3 2))

They should return:
“empty list”
0
14
30

PLACE THIS ORDER OR A SIMILAR ORDER WITH US TODAY AND GET A GOOD DISCOUNT

Expert paper writers are just a few clicks away

Place an order in 3 easy steps. Takes less than 5 mins.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00
Live Chat+1-631-333-0101EmailWhatsApp