The programming language is Emacs-Lisp.
Implement a function in Lisp that takes in one parameter that is a list and returns the previous to last element of the list.
If the list has less than two elements, it should return nil. Use the while loop for this function
check out the solution and do comment if any queries.
----------------------------------------
; function definition
(defun lastele (L)
; while loop - loop through list (havig length > 2) till it
reaches the list length == 2
(loop while (> (list-length L) 2)
do (setq L (cdr L)))
; check for list length == 2
(if (eq (list-length L) 2)
; if true then return the first element of the list which in turn
is 2nd last element
(car L)))
; function call and display accordingly
(print (lastele '(1 2 3 4 5 6 7)))
(print (lastele ()))
(print (lastele '(1 2)))
(print (lastele '(1)))
--------------------------------------------------
Code :
-----------------------
Output :

The programming language is Emacs-Lisp. Implement a function in Lisp that takes in one parameter that...