Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lisp Tutorial Click on Xlisp icon – you enter the interpreter

Similar presentations


Presentation on theme: "Lisp Tutorial Click on Xlisp icon – you enter the interpreter"— Presentation transcript:

1 Lisp Tutorial Click on Xlisp icon – you enter the interpreter
You can now Define functions Load program files – with .lsp extension Execute Lisp functions

2 > is the lisp prompt > mylist > (mylist)
Error: unbound variable mylist > (mylist) Error: unbound function mylist (setq mylist ‘(a b c d)) (A B C D)

3 (cdr (car mylist)) ? What will happen
(cdr mylist) (B C D) (car (cdr mylist) …waiting ) .. Need to complete the balanced parenthesis B (cdr (car mylist)) ? What will happen Error: bad argument type - A

4 > (equal nil mylist)
> (atom mylist) > (listp mylist) > (equal nil mylist)

5 > (null (cdr mylist) ) > (cdddr mylist) > (list (car mylist))
Error: unbound variable cdr > (null (cdr mylist) ) nil > (cdddr mylist) (D) > (list (car mylist)) (A) > (list (cdr mylist)) ((B C D))

6 LISP is NOT case sensitive
> (list (car mylist) (caddr mylist)) (A C) > mylist (A B C D) > (last mylist) ; as defined in the interpreter (D) > (cond ((null mylist) (print “ list is empty” ) ) ) NIL LISP is NOT case sensitive

7 > (cond ( (null mylist) (print “empty”)) )
> (equal ‘A ‘a) T > (cond ( (null mylist) (print “empty”)) ( t (print “not empty”) ) ) “not empty” Action print “not empty” Return “not empty”

8 > (cond ( (null mylist) (print “empty”)) )
( t mylist ) ) (A B C D) > (defun second (l ) (cadr l)) SECOND (second mylist) B

9 > (list (second mylist) (car mylist) (cddr mylist) )
(B A (C D)) Get the last element of a list Define this function Recursive definition

10 Define a function to reverse a list


Download ppt "Lisp Tutorial Click on Xlisp icon – you enter the interpreter"

Similar presentations


Ads by Google