1 / 8

Introduction to Artificial Intelligence Lisp

Introduction to Artificial Intelligence Lisp. Ruth Bergman Fall 2002. LISP. LISP (List Programming) invented by John McCarthy, Stanford, 1958 interpreted and compiled language many firsts (interpreter, garbage collection, debugger ....) Basic structure of LISP is the list atoms

aviv
Download Presentation

Introduction to Artificial Intelligence Lisp

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. Introduction to Artificial IntelligenceLisp Ruth Bergman Fall 2002

  2. LISP • LISP (List Programming) • invented by John McCarthy, Stanford, 1958 • interpreted and compiled language • many firsts (interpreter, garbage collection, debugger ....) • Basic structure of LISP is the list • atoms • quoted representation • cons • nil • car • cdr • null

  3. LISP Functions • Lisp expressions • quoted symbol • variable • functions • The easiest way to understand how Lisp operates is to understand the interpreter: • (loop (print (eval (read))) • read an expression (atom, quoted symbol, or list) • evaluate that expression • print the result

  4. LISP Functions • Lisp expressions • quoted symbol • variable • functions • Functions are prefix notation • cons, cdr, cddr, cdddr ... • arithmetic • list manipulations (append, list, cons) • (append ‘(a b) ‘(c d)) • (list ‘(a b) ‘(c d)) • (cons ‘(a b) ‘(c d)) • other lists (subst, last, length)

  5. LISP Variables • Variables can be declared, or created dynamically • (set ‘a ‘b) • (setq a ‘b) • (setf a ‘b) • We can even force evaluation • (setf a ‘b b ‘c) • (eval a)

  6. More Functions/Predicate • (defun fact (n) (if (= n 1) 1 (* n (fact (1- n))))) • values passed by value (copies) • variables are bound or free • variables are lexically scoped (dynamic is possible) • numberp • atom • listp • evenp, oddp • and/or/not

  7. Functions are Data • Notice that a function is just a list; we can manipulate it like data • (setq fun ‘fact) • (funcall fun 3)  6 • (apply #’fact ‘(3)) • We can define “anonymous” procedures • (funcall ‘(lambda (x) (list x)) 3)  (3) • (funcall (list ‘lambda ‘(x) ‘(list x)) 3) • We can also define local variables • (defun foo (x) (let ((a 1) (b 3)) (setq b (* x b)) (list a b x))) • There are lots of other “function functions” • map • reduce

  8. Some exercises • Define • reverse • flatten • member • union • intersection • difference

More Related