-
6
pages
-
English
-
Documents
Description
LISP Tutorial for CSC244/444 Hao Zhang Fall 2004 1. LISP = LISt Processing 1.1 lists, evaluations LISP is normally used as an interpreter. It interprets s-expressions, including lists and atoms. (1+ 1) ;1+ is the “increment by 1” function 2 Lists are defined recursively as sequences of lists or atoms (symbols or numbers). (1+ (1+ (1+ 1))) 4 Consequently, lists are interpreted recursively in a top-down fashion: (function-name arg_1 arg_2 … arg_n) At the bottom, numbers evaluate to themselves; symbols evaluate to the last value assigned to them. Notice that symbols serve the dual roles of function identifiers and variable specifiers in LISP. (setq 1+ 17) ;assigns 17 to the variable value of 1+, but the function value of 1+ is unchanged. 17 (1+ 1+) ;depending on the position of the symbol in the list, either the function value or the variable value will be retrieved. 18 1.2 setq and quote LISP has the tendency to evaluate everything. setq is named for set quote. It is special in that it actually quotes the first argument and takes it literally as a symbol. Using setq, a symbol, a number, a list, all can be assigned to a variable. We have the apostrophe character reserved for quote function. (setq a ’(1+ 1+)) (1+ 1+) (setq a ’1+) 1+ a 1+ (setq a ’( I saw (the man) (with (a telescope)))) ( I SAW (THE MAN) (WITH (A TELESCOPE))) ’() NIL 1.3 car, cdr, cadr, etc. cons, list, append Now, we can quote lists. The ...
-
Publié par
-
Langue
English