×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Program to Implement Basic Functions Using LISP Assignment Solution

July 01, 2024
Megan Talbot
Megan Talbot
🇺🇸 United States
Lisp
Meet Megan Talbot, a visionary Lisp wizard with a decade of metaprogramming mastery, sharing insights and guiding developers into the art of code enchantment.
Key Topics
  • Instructions
  • Requirements and Specifications
Tip of the day
When working on OCaml assignments, make use of pattern matching to simplify your code. It provides a clean and efficient way to handle different cases, especially for recursive functions and data structures like lists and trees. This can reduce complexity and improve readability.
News
Universities worldwide are seeing a surge in programming enrollment, as coding becomes an essential skill across disciplines. To meet growing academic pressures, more students are seeking online help for programming assignments and coursework.

Instructions

Objective 
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
;;1
(defun intmax (x y)
    (cond
      ((> x y) x)
      (T y)))
(print (intmax 2 4))
(print (intmax -1 -2))
(print (intmax 0 0))
(print (intmax -2 2))
;;2
(defun dup (elem)
  (cons elem (list elem)))
(print (dup 5))
(print (dup '(1 2 3)))
(print (dup 'a))
(print (dup nil))
;;3
(defun add-nums (x)
  (cond
    ((<= 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))
;;4
(defun backwards (lst)
  (cond
    ((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)))
;;5
(defun totalbackwards (lst)
  (cond
    ((null lst)
      lst)
    ((listp (car lst))
      (append (totalbackwards (cdr lst)) (list (totalbackwards (car lst)))))
    (t
      (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)))
;;6
(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)))

Related Samples

Explore Lisp Assignment Samples: Delve into our curated selection showcasing Lisp solutions covering recursion, list manipulation, and functional programming paradigms. From basic exercises to complex algorithms, each sample offers insights into Lisp programming. Strengthen your Lisp skills and excel in functional programming with our comprehensive examples.