Question

this is the be anwsered in the language scheme and it only

Question 2 (100 marks in total) Write a recursive function (split L) that takes a list L, and returns a new list containing t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Recursive function
;; makes two lists of every element
(define split
  (lambda (L)
    (if (null? L)
        '()
        (list (first L) (second L)))))

;; the first list 
(define first
  (lambda (L)
    (cond ((null? L) '())
          ((null? (cdr L)) L)
          (else (cons (car L)
                      (first (cdr (cdr L))))))))

;; the second list 
(define second
  (lambda (L)
    (cond ((null? L) '())
          ((null? (cdr L)) '())
          (else (cons (car (cdr L))
                      (second (cdr (cdr L))))))))

Q. What should split return if its input is an empty list? Explain why.

A: When input is an empty list it returns (). As in the code above we are checking whether given list is empty or not using condition. If the list is empty we are returning empty list ().

Add a comment
Know the answer?
Add Answer to:
This is the be anwsered in the language scheme and it only
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. The following function t(n) is defined recursively as: 1, n=1 t(n) = 43, n=2 -2t(n-1)...

    1. The following function t(n) is defined recursively as: 1, n=1 t(n) = 43, n=2 -2t(n-1) + 15t(n-2), n> 3 1. Compute t(3) and t(4). [2 marks] 2. Find a general non-recursive formula for the recurrence. [5 marks] 3. Find the particular solution which satisfies the initial conditions t(1) = 1 and t(2) = 43. [5 marks] 2. Consider the following Venn diagram, illustrating the Universal Set &, and the sets A, and C. А B cat,pig mouse, horse camel...

  • mammals.txt squirrel,2,0.5,Herbivore,Sciurus griseus kangaroo,7,90,Herbivore,Macropus rufus gorilla,20,150,Herbivore,Gorilla beringei sea lion,12,250,Carnivore,Zalophus californianus guinea pig,4,3,Herbivore,Cavia porcellus whale (grey),70,36000,Herbivor

    mammals.txt squirrel,2,0.5,Herbivore,Sciurus griseus kangaroo,7,90,Herbivore,Macropus rufus gorilla,20,150,Herbivore,Gorilla beringei sea lion,12,250,Carnivore,Zalophus californianus guinea pig,4,3,Herbivore,Cavia porcellus whale (grey),70,36000,Herbivore,Eschrichtius robustus cat,12,4,Carnivore,Felis catus sheep,12,180,Herbivore,Ovis aries giraffe,10,1000,Herbivore,Giraffa mouse,3,0.04,Omnivore,Mus musculus puma,12,50,Carnivore,Puma concolor orca,50,4000,Carnivore,Orcinus orca beaver,5,20,Herbivore,Castor canadensis fox,7,6,Omnivore,Vulpes vulpes donkey,12,300,Herbivore,Equus asinus buffalo,15,650,Herbivore,Bison bison cow,15,700,Herbivore,Bos taurus baboon,20,40,Omnivore,Papio ursinus horse,20,500,Herbivore,Equus ferus caballus moose,12,450,Herbivore,Alces alces goat,9,90,Herbivore,Capra aegagrus hircus chimpanzee,20,45,Omnivore,Pan troglodytes bear (grizzly),25,270,Omnivore,Ursus arctos leopard,12,55,Carnivore,Panthera pardus camel,40,500,Herbivore,Camelus dromedarius rhinoceros,40,2000,Herbivore,Ceratotherium simum simum hippopotamus,25,1400,Herbivore,Hippopotamus amphibius opposum,1,4,Omnivore,Didelphis virginiana howler monkey,15,7,Herbivore,Alouatta palliata deer,8,55,Herbivore,Odocoileus virginianus elephant,65,4500,Herbivore,Elephas maximus dog,12,25,Carnivore,Canis lupus familiaris bat,15,1,Omnivore,Pteropus vampyrus wolf,5,40,Carnivore,Canis lupus zebra,15,300,Herbivore,Equus quagga elk,15,280,Herbivore,Cervus...

  • write an SQL statement to list all the people in the Owner table, along with their...

    write an SQL statement to list all the people in the Owner table, along with their pets' names if any. That is, for each pet an owner has, there will be a record containing the owner and the pet's name. For any owner contained in the Owner table, the output should always contain the owner's record even if no pets are associated with this owner. Hint: outer join/s may be needed. -- DROP TABLE PetAndOwner, Pet, PetType, Owner; CREATE TABLE...

  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

  • Python Code help needed. Based on the file (2nd picture) a dictionary like the third picture...

    Python Code help needed. Based on the file (2nd picture) a dictionary like the third picture is to be made. def load_locations(filename): (str) -> dict Read data from the file with the given fi lename and create and return a dictionary with location data, structured as descr ibed in the ass ignment handout, Part 1 Section I1 [BEGIN DESCRIPTION There is nothing interesting here [END DESCRIPTION] BEGIN DESCRIPTION] You wake up lost in some unfamiliar place. All you know is...

  • Write a method called printReverse() that takes a string and uses recursion to print the contents...

    Write a method called printReverse() that takes a string and uses recursion to print the contents of the string in reverse order. The string itself should not be reversed; it must be left in its original form. The method has the following header:   void printReverse(String s, int i) where s is a reference to the string, and i is an integer parameter that you may use as you see fit. You do not need to code up this method as...

  • C++ Time the sequential search and the binary search methods several times each for randomly generated...

    C++ Time the sequential search and the binary search methods several times each for randomly generated values, then record the results in a table. Do not time individual searches, but groups of them. For example, time 100 searches together or 1,000 searches together. Compare the running times of these two search methods that are obtained during the experiment. Regarding the efficiency of both search methods, what conclusion can be reached from this experiment? Both the table and your conclusions should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT