Question

In: Computer Science

Use Scheme Language Write a Scheme function that takes a list and returns a list identical...

Use Scheme Language

Write a Scheme function that takes a list and returns a list identical to the parameter except the third element has been deleted. For example, (deleteitem '(a b c d e)) returns ‘(a b d e) ; (deleteitem '(a b (c d) e)) returns ‘(a b e).

Solutions

Expert Solution

Code to Copy;

   (define (deleteitem list)
   (unless (or (null? list)
               (null? (cdr list))
               (null? (cddr list)))
       (set-cdr! (cdr list) (cdddr list)))
   list)

   (display (deleteitem '(a b c d e)))

(display (deleteitem '(1 2 3 4 5)))

(display (deleteitem '(a b (c d) e)))

Output Screenshots:

i). output for  (display (deleteitem '(a b c d e)))

ii). output for (display (deleteitem '(1 2 3 4 5)))

iii). output for   (display (deleteitem '(a b (c d) e)))


Related Solutions

scheme: Write a recursive Scheme function (subst x y L), which returns a list identical to...
scheme: Write a recursive Scheme function (subst x y L), which returns a list identical to L except that every occurrence of x has been replaced with y. The following example illustrates the use of this function: > (subst 'c 'k '(c o c o n u t)) (k o k o n u t) Write a recursive Scheme function (all-different? L), which determines whether all elements of list L are distinct (that is, not equal?). The following example illustrates...
Write a function that takes a list of integers as input and returns a list with...
Write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2] Do not use any special or built in functions like append, reverse etc.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
We were asked this: Write a function that takes a list, and returns a list representing...
We were asked this: Write a function that takes a list, and returns a list representing each word whose reverse is also in the list. def find_reversals(lst: List[str]) -> List[str]: Each pair, such as 'abut', 'tuba', should be represented by the first element encountered. Don't report the same pairs twice. Don't list palindromes. I wrote this, which might not be optimal but passes the unit test! def find_reversals(lst): #Place to save to found_reversals=[]    #Make each string lowercase for i...
USING PYTHON, write a function that takes a list of integers as input and returns a...
USING PYTHON, write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2]. DO NOT use any special or built in functions like append, reverse etc.
1.Write a function div7(lst) which takes in a list of integers, and returns a list of...
1.Write a function div7(lst) which takes in a list of integers, and returns a list of booleans of the same length, such that for each integer in the original list, the boolean in the output list is True if that integer was divisible by 7, or False if not. Use list comprehensions in python, the function only could be at most two lines long. Here is some examples: >>> div7([14, 5, 7, 3, 29, 28, 10]) [True, False, True, False,...
Write a LISP function COUNTX which takes an atom and a list and returns the number...
Write a LISP function COUNTX which takes an atom and a list and returns the number of top-level occurrences of the atom in the list. For example: (COUNTX ‘A ‘(A (A B) B A B A (B A)) Returns the value 3, the other two A’s are not at the top level
In DrRacket Write a function, removeAll, which takes two lists, list-a and list-b and returns a...
In DrRacket Write a function, removeAll, which takes two lists, list-a and list-b and returns a list containing only the items in list-a that are not also in list-b. E.g., (remove-all '(a b b c c d) '(a c a)) -> '(b b d)
SML Complete the following programs. 1. Write a function listify that takes a list and returns...
SML Complete the following programs. 1. Write a function listify that takes a list and returns a list of lists where each element of first list becoming its own single-element list (Fill in the code here) fun main() = let val lst = (explode "rad"); in print (PolyML.makestring ( listify lst )) end; 2. Write a function splitlist that takes a list of pairs and returns a pair of lists that has the firsts of the pairs in one list...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT