Programming a few procedures in 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.
(addNonEmptyList ‘(1 2 3))
(addNonEmptyList ‘(1 4 3 2))
They should return:
PLACE THIS ORDER OR A SIMILAR ORDER WITH US TODAY AND GET A GOOD DISCOUNT
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.Read more
Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.Read more
Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.Read more
Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.Read more
By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.Read more