1 / 10

Lisp Tutorial

Lisp Tutorial. Click on Xlisp icon – you enter the interpreter You can now Define functions Load program files – with .lsp extension Execute Lisp functions. > is the lisp prompt > mylist Error: unbound variable mylist > (mylist) Error: unbound function mylist (setq mylist ‘(a b c d))

finna
Download Presentation

Lisp Tutorial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 • Error: unbound variable mylist • > (mylist) • Error: unbound function mylist • (setq mylist ‘(a b c d)) • (A B C D) • > mylist • (A B C D)

  3. (car mylist) • A • (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. > nil • nil • > t • t • > (atom mylist) • nil • > (listp mylist) • t • > (equal nil mylist) • nil

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

  6. > (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. > (equal ‘A ‘a) • T • > (cond ( (null mylist) (print “empty”)) • ( t (print “not empty”) ) • ) • “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

More Related