






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
commands of lisp programming language cheers
Typology: Exams
1 / 12
This page cannot be seen from the preview
Don't miss anything!







LISP: LISt Processing Language
- An AI language developed in 1958 (J. McCarthy at MIT)
Basic LISP Commands: Create list in LISP and perform various commands: List1: sub (CO, PPL, DELD, OOP, Math) List2: marks (10, 20, 30, 40) set setf setq car (first) cdr (rest) reverse append cons length nth nthcdr butlast last User defined Functions Note: sub and marks these are the names of set which are created using set command. All other commands are performed on both the sets.
preceding . It returns the result of evaluating the last . If no - pairs are specified, setf returns nil.
(setf
. . ) : either (i) the name of a variable, or (ii) an expression referring to part of a larger structure (e.g. a list, property list, structure, or array). : any LISP expression. eg.
(car ) / (first )
*(car ‘(a b c d e f))) A ;output *(first '(a)) A ;output *(car ‘(PPL CO DELD)) PPL ;output
(cdr ) / (rest )
*(cdr ‘(a b c d e f))) (B C D E F) ;output *(rest '(a)) Nill
***** (cons sub marks) ((PPL OOP CO DELD) 10 20 30 40)
syntax: (length ) eg. *(length '(1 2 3 4 5 6 7)) 7 ;output
syntax: (nth ) eg. *(nth 0 '(p r w c)) P ;output
*(nth 2 '(p r w c)) W
eg.
element removed and if butlast is given an integer second argument then it will remove the number of elements specified from the end of the list.
(butlast ) (butlast )
Use defun to define user define functions in LISP. Defun requires you to provide three things. the first is the name of the function , the second is a list of parameters for the function, and the third is the body of the function -- i.e. LISP instructions that tell the interpreter what to do when the function is called Definition of a function: Syntax: (defun ) ; a LISP function for Addition of two numbers
; a LISP function to calculate the factorial of number (defun factorial (N) "Compute the factorial of N." (if (= N 1) 1 (* N (factorial (- N 1))))) (write (factorial 6)) 720 ;output ; a LISP function which returns the maximum of three numbers (defun maxthree(n1 n2 n3) (cond ((> n1 n2) (cond ((> n1 n3) n1) (t n3) ) ) ((> n2 n3) n2) (t n3) ) ) (princ (maxthree 45 64 9)) 64 ;output To execute the .lisp file on sbcl ,use command load and .lisp file name square.lisp containing this below mentioned code: (defun sr(n) ( * n n)) Syntax: (load “< .lisp file name>”) It will return T as a true