Docsity

Learning Lisp: A Programming Language with Quick Features and Flexibility, Slides of Robotics

Partial preview of the text

Download Learning Lisp: A Programming Language with Quick Features and Flexibility and more Slides Robotics in PDF only on Docsity!

Why Lisp?

  • Because it’s the most widely used AI programming

language

  • Because AI researchers and theoreticians like using it
  • Because it’s good for writing production software (Graham

article)

  • Because it’s got lots of features other languages don’t
  • Because you can write new programs and extend old

programs really, really quickly in Lisp

  • Lisp stands for “LISt Process”
    • Invented by John McCarthy (1958)
    • Simple data structure (atoms and lists)
    • Heavy use of recursion
    • Interpretive language
  • Variations
    • Frantz Lisp (80’s)
    • Common Lisp (de facto industrial standard)
  • Common Lisp at gl.umbc.edu and

sunserver1.csee.umbc.edu

2. Function calls

  • also a list
  • use prefix notation: (function-name arg1 ... argn)
  • returns function value for the given list of arguments
  • functions are either provided by Lisp function library or defined by the user.
  • Examples:

    (+ 1 3 5) 9 (/ 3 5) 3/ (/ 3.0 5) 0. >(sqrt 4) 2

  • Sqrt
  • +

  • (^) Docsity.comload
  • Atoms
  • numeric
  • fractions
  • floating point
  • literal atoms
  • Boolean

values

  • other symbols
  • strings
  • Function

calls

  • evaluation

of functions

  • setf more

general than

setq

  • binding
  1. To assign a value to a symbol ( setq, set, setf )
  • setq is a special form of function (with two arguments);
  • the first argument is a symbol which will not be evaluated;
  • the second argument is a S-expression, which will be evaluated;
  • the value of the second argument is assigned to be the value of the first argument
  • to forbid evaluation of a symbol ( quote or ‘ )

(setq x 3.0)

x

(setq y x)

; the value of x is assigned as the value of y

y

(+ x y)

-. to force an evaluation, using function " eval "

Two more assignment functions: (set x y) ; assign the value of y to the value of x. x is evaluated ; first and whose value must be a symbol ; "setq" is a combination of "set" and "quote" (setf x y) ; similar to but more general than "setq" in that x can be ; something other than a symbol.

(quote x) x

'x x

(setq z 'x) x

(+ x z) Error: X is not of type NUMBER ...

(+ x (eval z))

eval

  • car
  • cdr
  • cadr
  • caddr
  • nthcdr
  • butlast
  • cons
  • append
  • length
  • reverse
  • last
  • list

2) Predicates (a special function which returns NIL if the predicate is false, T or anything other than NIL, otherwise) = , > , < , >= , <= for numerical values; equal, eq, for others (symbols, lists, etc.)

tests if x is a atom

tests if x is a list

also numberp, symbolp, null

(< x y) NIL

(= x y) T

(equal ‘x ‘y) NIL

(equal ‘a (car L)) T

(atom L) NIL

( listp x) NIL

( listp L) T

( atom x) T

(numberp ‘x) NIL

( atom ( car L)) T

(numberp x) T

(symbolp ‘ x) T

(symbolp x) NIL

predicates

  • Basic storage

handling