Question

Write a LISP function REMOVELAST which removes the last element of a given list. For example:...

Write a LISP function REMOVELAST which removes the last element of a given list. For example: (REMOVELAST ‘(A (A B) C)) Returns the list (A (A B)) and (REMOVELAST ‘(A B (C D))) Returns the list (A B)

Homework Answers

Answer #1

(defun REMOVELAST(list)
(reverse (cdr (reverse list)))
)

first the inner reverse will be executed and it will reverse the list.
Now the last element is the first element.

now we use cdr which will return the list without the first element.
So the last item of the origiinal list has been removed.

Now we reverse it again, so now we have the origiinal list without the last element

Know the answer?
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
Similar Questions
You can only use built in Lisp functions and you cannot use setq function. Write a...
You can only use built in Lisp functions and you cannot use setq function. Write a function in Lisp called f7 that returns the element at a given location of a list. The locations start at 0. Example: (f7 ‘(c (a b) (d c) (x y)) 2) returns (d c)
You can only use built in Lisp functions and you cannot use setq function. Write a...
You can only use built in Lisp functions and you cannot use setq function. Write a function f2 that decides whether a list has an atom inside. Example: (f2 ‘((a b)(c d))) returns nil, (f2 ‘(a (b c))) returns t
Task 1: Program Analysis Write a function cutEdges that removes the first and the last two...
Task 1: Program Analysis Write a function cutEdges that removes the first and the last two items from a list given as its argument.  The existing list should be changed in-place; the function should not return anything..programmed in python
(1)Create a LISP function FLATTEN, a function that returns all the elements of an arbitrarily nested...
(1)Create a LISP function FLATTEN, a function that returns all the elements of an arbitrarily nested list in a single-level list. (FLATTEN ’((A B (R)) A C (A D ((A (B)) R) A))) should return (A B R A C A D A B R A). (2) Create a Lisp function EXP-EVAL, a function that evaluates an arithmetic expression. You may assume that the binary operators used for an arithmetic expression are: +, -, *, and /, and each of...
Write a LISP function that accepts two lists as it's only arguments. The function should return...
Write a LISP function that accepts two lists as it's only arguments. The function should return a new list with the arguments as it's elements. So, if you pass the function (a b c) and (1 2 3), the function should return ((a b c) (1 2 3)).
Write a Python function uniqueLast(S) that returns True if and only if the last element of...
Write a Python function uniqueLast(S) that returns True if and only if the last element of sequence S is unique in S. Specify any special cases
Write a recursive function elemAt that returns the ith item of the list, where the first...
Write a recursive function elemAt that returns the ith item of the list, where the first item is index 0. You may not use any of the standard Haskell functions that operate on lists. For Example: List is [5,6,7,78,8,7]          Element at index 3 is 78
4. Write a Java program to test if the first and the last element of an...
4. Write a Java program to test if the first and the last element of an array list of integers are same 5. Write a Java program to test if the first and the last element of two array list of integers are same
Write a function that returns the largest element of an array? Your function should accept a...
Write a function that returns the largest element of an array? Your function should accept a 1-D array as an input and return the largest number. You may assume all numbers are integers. CODE IN C++ PLEASE
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum...
Write a PYTHON function called myMax which accepts a LIST of numbers and returns the maximum number in the list. Do NOT use Python’s built-in function max. Example: result = myMax([-999000, -1000000, -2000000]); print(result) #output is -999000 Example: result = myMax([1000000, 1000001, 1000002]); print(result) #output is 1000002