![]() |
Department of
Mathematics and Computer Science |
|
math 22: lisp AKCL (Austin Kyoto Common Lisp) Version(1.619) Thu Oct 7 15:46:49 PDT 1993 Contains Enhancements by W. Schelter > (load "foo.lsp")(Also see the sample "typescript" session.)
(COND (condition1 action1)
(condition2 action2)
(condition3 action3)
...
(condition_m action_m) )
--the last condition can be replaced by T or omitted.(DEFUN function_name input_var_list action)
(PRINT a) --- prints the value of a (on the terminal)To OPEN file FOO.LSP in your directory and prepare it as an INPUT file:(TERPRI) --- induces a carriage return
(SETQ IN1 (OPEN "FOO.LSP" :DIRECTION :INPUT))where IN1 can be any local atom.
Then to READ from file FOO.LSP, use:
(READ IN1)reads one s-expression
(READ-CHAR IN1)reads one character
To CLOSE the file:
(CLOSE IN1)To OPEN file BAR.LSP in your directory and prepare it as an OUTPUT file:
(SETQ OUT1 (OPEN "BAR.LSP" :DIRECTION :OUTPUT))Then to PRINT to BAR.LSP, use:
(PRINT s_exp OUT1) -- prints in form which can later be used by READ with a preceding NEWLINE and followed by SPACE (i.e., with escape characters).(PRIN1 s_exp OUT1) -- prints in form which can later be used by READ without any surrounding spaces (i.e., with escape characters).
(PRINC s_exp OUT1) -- like PRIN1 except special characters are printed without other marks (i.e., NO escape characters).
(TERPRI OUT1) -- forces a carriage return in file OUT1.
(SETF (GET x z) y) -- gives x the z-property of y.
[OTHER LISPs may use (PUTPROP x y z)]
E.g., (setf (get 'book 'date) 1988) gives the atom book a date property and assigns the value of 1988 to that property.(GET x z) -- gets the value of the z-property of x.
(LOAD "FOO.LSP")
(bye)
:q
(TRACE funct) turns on function call and return tracing.
(UNTRACE funct) turns off tracing.
(HELP) or (HELP 'Lisp_element) or (DESCRIBE 'Lisp_element), e.g., (DESCRIBE 'CAR) or (DESCRIBE 'PRINT) or (APROPOS "Lisp_concept"), e.g. (APROPOS "READ")
One can invoke the Unix "vi" editor on a file WHILE IN LISP through the command (ED "filename.LSP"). To return to LISP, use :w and :q.
math 20: script
Script started on Wed Apr 7 21:11:37 1999
math 21: more foo.lsp
(defun for (a)
(prog ()
loop (print (car a))
(setq a (cdr a))
(cond ((not (null a)) (go loop)))))
(defun rev (x)
(cond ((null (cdr x)) (print (car x)))
((prog () (rev (cdr x))
(print (car x))))))
math 22: lisp AKCL (Austin Kyoto Common Lisp) Version(1.619) Thu Oct 7 15:46:49 PDT 1993 Contains Enhancements by W. Schelter >(+ 1 2) 3 >(setq a 2) 2 >(setq b '(a 2 3)) (A 2 3) >(car b) A >(cdr b) (2 3) >(cons '+ (cdr b)) (+ 2 3) >(setq c (cons '+ (cdr b))) (+ 2 3) >c (+ 2 3) >(eval c) 5 >(load "foo.lsp") Loading foo.lsp Finished loading foo.lsp T >(setq d '(1 2 3 4 5 6 7)) (1 2 3 4 5 6 7) >d (1 2 3 4 5 6 7) >(rev d) 7 6 5 4 3 2 1 NIL >(for d) 1 2 3 4 5 6 7 NIL >(bye) Bye. math 24: exit math 25: script done on Wed Apr 7 21:13:45 1999
My email address is
dsmolarski@math.scu.edu
This page last updated 14 March 2000.