LISP Programs 1. To Perform Primitive Operations (I.e CAR, CDR, APPEND)
LISP Programs 1. To Perform Primitive Operations (I.e CAR, CDR, APPEND)
OUTPUT :
Enter the list1 : (1 2 3)
Enter the list2 : (4 5 6)
The CAR of 1st list is : 1
The CDR of 1st list is : (2 3)
The appended list is : (1 2 3 4 5 6)
OUTPUT:
Enter the range : 7
Sum of given number is : 28
(defun quit()
(format t"~%Exit"))
(format t"~%Enter initial")
(setq stack(read))
(menu)
(setq code(read)ch'y)
(do() ((not(EQL ch'y))nil)
(case code
(1 (push))
(2 (pop))
(3 (quit)))
(cond((= code 3)(setq ch 'n))
(t (format t"~% Do you want to continue(y/n):")
(setq ch(read))
(cond ((EQL ch'y)
(menu)
(setq code(read)))
(t (setq code 3))
))))
OUTPUT:
Enter initial4
press 1 to perform push operation
press 2 to perform pop operation
press 3 to quit
Enter ur choice1
stack before push:4
Enter data to be pushed:12
Stack after push operation(12)
Do you want to continue(y/n):y
OUTPUT:
Enter the List: (2 3 4 5)
Reversed list is : (5 4 3 2)
7. To perform function powerset that takes a list l as input & returns the powerset of the list
(defun powerset(l)
(if (null l)
'(nil)
(let ((ps (powerset (cdr l))))
(append ps(mapcar #'(lambda (x) (cons (car l) x)) ps)))))
(format t"~% Enter the list : ")
(setf l(read))
(format t"~% Powerset : ~a" (powerset l))
OUTPUT:
Enter the list : (1 2 3)
Powerset : (NIL (3) (2) (2 3) (1) (1 3) (1 2) (1 2 3))
OUTPUT:
Enter number : 5
Factorial = 120
OUTPUT:
Enter the numbers :
242
; Autoload: SQRT from "TRANCEND" in "C:\\GCLISP\\LISPLIB\\". Root = -1.0D0