+1 (315) 557-6473 

Program to Implement Basic Functions Using LISP Assignment Solution.


Write a program to implement basic functions using the LISP programming language.

Requirements and Specifications

Function intmax to return the greatest number among two integers.
Function dup which takes an element and returns a tuple with the element duplicated .
Recursive function to add up all numbers from 1 to a given upper limit.
Function backwards to return the reverse order list of a given input list but no sublists .
Function totalbackwards to return total reverse order list .
Function with algorithm to detect palindrome.
Screenshots of output
implementing functions with basic LISP
Source Code
(defun intmax (x y)
      ((> x y) x)
      (T y)))
(print (intmax 2 4))
(print (intmax -1 -2))
(print (intmax 0 0))
(print (intmax -2 2))
(defun dup (elem)
  (cons elem (list elem)))
(print (dup 5))
(print (dup '(1 2 3)))
(print (dup 'a))
(print (dup nil))
(defun add-nums (x)
    ((<= x 1) 1)
    (t (+ x (add-nums (- x 1))))))
(print (add-nums 1))
(print (add-nums 5))
(print (add-nums 10))
(print (add-nums -1))
(defun backwards (lst)
    ((null lst) lst)
    (t (append (backwards (cdr lst)) (list (car lst))))))
(print (backwards '(a b c h i)))
(print (backwards nil))
(print (backwards '(a (b c) (h i))))
(print (backwards '(a)))
(defun totalbackwards (lst)
    ((null lst)
    ((listp (car lst))
      (append (totalbackwards (cdr lst)) (list (totalbackwards (car lst)))))
      (append (totalbackwards (cdr lst)) (list (car lst))))))
(print (totalbackwards '(a (b c) ((l k (t)) h i))))
(print (totalbackwards nil))
(print (totalbackwards '((a b) ((c d) e))))
(print (totalbackwards '(a b () c d)))
(defun palindrome (lst)
  (equal lst (backwards lst)))
(print (palindrome '(r o t o r)))
(print (palindrome '(r a c e c a r)))
(print (palindrome '(p a l i n d r o m e)))
(print (palindrome '(r a c e c a r s)))