Interactive Powerpoint_How to Master effective communication
Lisp.pptx
1. Ranjitha M
Department of Computer Science [PG]
Kristu jayanti College[Autonomous]
Bengaluru
Lisp -Local Variables
2. Constructs for local variables
->(setq ‘(a b c))
(A B C)
->(setq ‘(d e f))
(D E F)
->(defun local-var (x)
(setq y(cons x y)))
LOCAL –VAR
->(local-var 6)
(6 A B C)
->x
(D E F)
->y
(A B C)
->
x variable is local and the variable y is global.
It is accessible from any procedure and retains its value unless reset with setq.
3. The let and prog constructs also permits the creation of local variables.
Syntax:
(let ((var1 val1) (var2 val2)…) <s-expressions>)
->(let((x ‘a)
(y ‘b)
(z ‘c))
(cons x (cons y (list z))))
(A B C)
->
->(defun memb (el 1st)
(prog ()
start
(cond ((equal el (car 1st )) (return 1st)))
(setq 1st (cdr 1st))
(go start)))
MEMB
->
4. ITERATION AND RECURSION
(do(<var1 val1> <var-update1>)
(<var2 val2> <var-update2>)
. .
(<test> <return-value>)
(<s-expressions>))
->(defun factorial(n)
(do ((count n (- count 1))
(product n(* product (- count 1))
((equal 0 count) product)))
FACTORIAL
->
Loop has a simple form
(loop <s-expression>)