Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute LISP Online

(SETQ L '(A B C D))
(DEFUN my-first (LST)
    (CAR LST))
(DEFUN my-rest (LST)
    (CDR LST))
(DEFUN my-construct (A LST)
    (CONS A LST))
(DEFUN rotate-left (LST)
    (APPEND (CDR LST) (LIST(CAR LST))))
(DEFUN rotate-right (LST)
    (APPEND (LAST LST)(REVERSE(CDR(REVERSE LST)))))
(DEFUN palindrom (LST)
    (APPEND LST (REVERSE LST)))
(DEFUN EC2 (A B C)
    (LIST (/ (+ (- B) (SQRT (- (* B B) (* 4 (* A C))))) (* 2 A)) (/ (- (- B) (SQRT (- (* B B) (* 4 (* A C))))) (* 2 A))))
(DEFUN my-evenp (A)
    (if (ZEROP (REM A 2)) (write t) (write nil)))
(DEFUN my-palindromp (LST)
    (if(EQUAL LST (REVERSE LST)) (write t) (write nil)))
(DEFUN not-realp(A B C)
    (if(MINUSP (- (* b b) (* 4 a c))) (write t) (write nil)))
(format t "My first CAR:")
(print (my-first L))
(format t "~%My first CDR:")
(print (my-rest L))
(format t "~%My first CONS:")
(print (my-construct '(X) L))
(format t "~%Rotate Left:")
(print (rotate-left L))
(format t "~%Rotate Left Twice:")
(print (rotate-left (rotate-left L)))
(format t "~%Rotate Right:")
(print (rotate-right L))
(format t "~%Rotate Right Twice:")
(print (rotate-right (rotate-right L)))
(format t "~%Palindrome of the list with double length:")
(print (palindrom L))
(format t "~%Roots of ecuation:")
(print (EC2 1 -5 6))
(format t "~%Checking if Even~%")
(my-evenp (* 15 2))
(format t "~%Checking if Palindrome~%")
(my-palindromp L)
(format t "~%Checking if Not Real~%")
(not-realp 1 -2 6)
(SETQ A -10)
(SETQ B 7)
(SETQ C nil)
(COND ((MINUSP A) (format t "~%Value of abs(~d) is:~d~%" a (- a))) (t (format t "~%Value of abs(~d) is:~d~%" a a)))
(COND ((> A B) (format t "Maximum of ~d and ~d is:~d~%" a b a)) (t (format t "Maximum of ~d and ~d is:~d~%" a b b)))
(COND ((< A B) (format t "Minumum of ~d and ~d is:~d~%" a b a)) (t (format t "Minimum of ~d and ~d is:~d~%" a b b)))
(COND ((NOT A) (write t)) (t(write nil)))
(format t "~%")
(COND ((NOT C) (write t)) (t(write nil)))
(format t "~%")
(COND ((OR A B C) (write t))(t(write nil)))
(format t "~%")
(COND ((AND A B C) (write t))(t(write nil)))
(print (cons(car nil)(cdr nil)))
(format t "~%")
(DEFUN MEDIAN-OF-THREE(A B C)
    (COND((AND (> A B)(< A C)) (write A))
        ((AND (< A B)(> A C)) (write A))
        ((AND (< B A)(> B C)) (write B))
        ((AND (< B C)(> B A)) (write B))
        ((AND (< C B)(> C A)) (write A))
        ((AND (< C A)(> C B)) (write A))))
(MEDIAN-OF-THREE 20 25 12)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.