120 likes | 286 Views
Using Harlequin LispWorks. Using LispWorks. On BURKS 5, the file is lwper410.exe Start up LispWorks; you get two windows Listener 1 LispWorks Personal Edition In the LispWorks Personal Edition window, use Tools -> Editor to open a third window ( Editor 1 ). The Windows.
E N D
Using LispWorks • On BURKS 5, the file is lwper410.exe • Start up LispWorks; you get two windows • Listener 1 • LispWorks Personal Edition • In the LispWorks Personal Edition window, use Tools -> Editor to open a third window (Editor 1)
The Windows • Use the Listener 1 window to evaluate Lisp expressions directly • CL-USER 1 > (car '(a b c))A • Case doesn't matter in LispWorks • In the Editor 1 window, use the Text tab, and use this window to define functions
Editing • Edit as usual in the Editor window • If you know emacs, you can use emacs commands in this window • If you don’t know emacs, you are not missing anything essential • Save and Save As… work as usual
Compiling • Use Buffers -> Compile to compile your functions into the Listener window • Sometimes the Buffers -> Compile command is on a menu in the LispWorks Personal Edition window • If so, go to Listener -> View -> Options and check Each tool has its own menu bar • Test functions in the Listener window
Loading Previously Saved Files • Use File -> Compile and Load… • or use the Lisp LOAD function:(load "C:\\Lisp\\myprog.lsp")
Saving a Transcript • You need to save and print a transcript of the tests of your function • The Listener window doesn’t have any Save commands • Keyboard editing shortcuts don’t work • But Select All and Copyare on the Edit menu.
Example: Searching an AV List • In the Editor window, enter: (defun lookup (a pairs) (cond ((null pairs) nil) ((eq a (car (car pairs))) (cdr (car pairs))) (t (lookup a (cdr pairs))) ) )
Compiling • In the Editor window, click Buffers -> Compile • It says "Press Space to continue", so do so • Try the function in the Listener window: • CL-USER 20 : 2 > (lookup 'b '((a x)(b y)(c z)))(Y) • That’s wrong-- we should get Y, not (Y); go back to the Editor window to fix it
Repairing a Function • Change the function in the Editor window: (defun lookup (a pairs) (cond ((null pairs) nil) ((eq a (car (car pairs))) (car (cdr (car pairs)))) (t (lookup a (cdr pairs))) ) ) Then compile it and try it again
More Built-In Functions • (CAR (CAR X)) --> (CAAR X) • (CAR (CDR X)) --> (CADR X) (defun lookup (a pairs) (cond ((null pairs) nil) ((eq a (caar pairs)) (cadar pairs)) (t (lookup a (cdr pairs))) ) )