In LISP write one function using length that gets the last atom in a list and another function that triples all the elements in a list (triple-value '(1 2 3 4 5)) so the result should be (1 8 27 64 125)
Code to find the last element from the list
(defun last_element(input_list)
(loop for i in input_list
do (setf last i))
)
(defvar last 0)
(last_element '(1 2 3 4))
(princ "Last element of the list is: ")
(write last)
Input Snippet

Output

Code to find the triple of all elements of the list
(defun triple-value(input_list)
(loop for i in input_list
do (setf i (* i (* i i)))
(setf cubed (append cubed (list i)))
)
)
(defvar cubed (list))
(triple-value '(1 2 3 4))
(princ "The Tripled List is : ")
(write cubed)
Input

Output

Please let me know if you have any queries in the comments below. Thank you!
In LISP write one function using length that gets the last atom in a list and...
Explain this lisp recursive function that gets the length of a list. ; a recursive function to find the lenght of the list (defun len (list) (if list (1+ (len (cdr list))) 0)) What does the 1+ and the 0 at the end do?
1. Write a Lisp function called piece which takes a single argument x and implements the following piecewise linear function: piece(x) = x if 0 < x < 1 2. Write a Lisp function called intList which takes two integer arguments, a and b and returns the list of all integers from a to b (inclusive at both ends). For example, (intList 3 8) should return (345678)
1. Write a Lisp function called piece which takes a single argument x...
In Lisp programming language
a 16. (20 pts.) Write a function that takes a list of 0's and l's and "toggles" each element. Your function should include lambda expression that knows how to flip an individual element, plus an applicative operator to do this to every element of the list. Example: 1 0) List (0 0 1 1 0 1) should be transformed into (1 1 0 0
2. Write a LISP function COUNTLETS which takes a list and returns the number of top-level alphabetic atoms in the list. For example: COUNTLETS ( (A 2) B 3 C4 (D 5))) Returns the value 2, the letters A and D are not at the top level
def append_length(my_list): """ Append the length to a list Finish this function which gets the length of a list, then append the length (as an integer) to the list. For example, if the parameter my_list is [0,1,2,3], after running this function, a 4 will be appended to this list: [0, 1, 2, 3, 4] This function does not have any explicit return value. Micro-credential(s): - Applying basic operations/operators (including len(), concatenation, repetition and in operator) to lists - Adding an...
Define a function named insert that takes an integer atom and a sorted list as parameters. The function should return a list with the integer in the correct position in the sorted list. For example: insert [3, (2 4 6 8)] = (2 3 4 6 8) insert 9, ()] = (9) insert[3, (2 3 4 5)] = (23 3 4 5) Note that in the case of that last example, it does not matter which 3 comes first in...
Objective To program using the functional programming paradigm Assignment: Write the following functions using Scheme (or LISP if you prefer) . A function (binomial N k) that returns the binomial coefficients C(N, k), defined recursively as: C(NO) = 1, C(N, N) = 1, and, for 0<k < N E(N, k) = C(N-1, k) + C(N-1, k-1) 2. A function (mod N M) that returns the modulus remainder when dividing N by M 3. A function (binaryToDecimal b) that takes a...
Using Java, write a recursive method that receives only one parameter, an int n, and prints the cubed of the numbers from 1 to n3 in descending order. Do not use any global variables or stacks. For example, passing this method the value 5, the output would be “125 64 27 8 1”. Because 13 = 1, 23 = 8, 33 = 27, 43 = 64 and so on.
Write a Python function fun3(e) to update a list of numbers e such that the first and last elements have been exchanged. The function needs to also return multiplication of elements of e. You should assume that the list e has at least 2 elements. Example: >>>lst = [4, 1, 2, -1] >>>fun3(list) -8 >>>lst [-1, 1, 2, 4] *We are an intro to CS class so please do not use anything too advance or fancy. Stick to basics. Right...
Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...