Allegro CL Certification Program Lisp Programming Series Level

  • Slides: 14
Download presentation
Allegro CL Certification Program Lisp Programming Series Level I Session 1. 1. 4 Basic

Allegro CL Certification Program Lisp Programming Series Level I Session 1. 1. 4 Basic Lisp Development in the IDE

Starting the IDE • From the Windows start menu, start the development environment •

Starting the IDE • From the Windows start menu, start the development environment • The windows you get: – Menu bar across the top – Debug window – Untitled Edit window – Form window – Inspect window

Creating a Source File • Find the Edit window (which is initially titled Untitled)

Creating a Source File • Find the Edit window (which is initially titled Untitled) – View > Editor • Initially, there is a tab named Untitled. (If there is not, create one via File > New. ) • Enter the following source code: (in-package : user) (defun square (x) (* x x)) – Note the cursors help balance parentheses

Warning • Put all important source code into files • Don’t type source code

Warning • Put all important source code into files • Don’t type source code into the debug window! – It won’t be saved if you exit Allegro! – Use debug window only for performing small experiments

Compile Your Code • Click on the “truck” icon to compile and load the

Compile Your Code • Click on the “truck” icon to compile and load the current source file • OR Click on the (=>) icon to compile the definition under the cursor

Run Your Code • Bring up the Debug window • Change to the package

Run Your Code • Bring up the Debug window • Change to the package where the symbols in your application live • Run the new function CG-USER(5): (in-package : user) #<The COMMON-LISP-USER package> CL-USER(6): (square 7) 49 CL-USER(7):

Debug your code • Type (squar 7) into the debug window – Function name

Debug your code • Type (squar 7) into the debug window – Function name is intentionally misspelled • Error: attempt to call 'SQUAR' which is an undefined function. • You can – Invoke Selected Restart • Pick from a menu of predefined error handlers – Debug • Starts the Lisp Debugger – Abort • Exits the debugger and returns you back to the top level • This is the same as the "Return to Top Level" restart

The Lisp Debugger • Click 'Debug' on the error window to get here •

The Lisp Debugger • Click 'Debug' on the error window to get here • Button bar across top – Click on the big “X” to get back to top level • Display area shows call stack – The bottom of the call stack shows the functions being used by the IDE itself to evaluate the line of code you just typed • Debug area for evaluating expressions in the current environment

What You Can And Can't Do • You can see the call stack, including

What You Can And Can't Do • You can see the call stack, including values of all the arguments • You can to see local variables, given the proper declaration (defun foo (x) (declare (optimize (debug 3))) (let ((y (cons 2 3))) (cons x y))) • You can't step line-by-line through your source code

How to Set a Breakpoint (defun foo (x) (declare (optimize (debug 3))) (let ((y

How to Set a Breakpoint (defun foo (x) (declare (optimize (debug 3))) (let ((y (cons 2 3))) (BREAK) (cons x y)))

Tracing Function Execution • Put this in your source file: (defun add (a b)

Tracing Function Execution • Put this in your source file: (defun add (a b) (+ a b)) (defun sum-squares (x y) (add (* x x) (* y y))) • Type three things to the debug window: (trace add) (trace sum-squares) (sum-squares 3 4)

Interpreting Trace Output 0[1]: (SUM-SQUARES 3 4) 1[1]: (ADD 9 16) 1[1]: returned 25

Interpreting Trace Output 0[1]: (SUM-SQUARES 3 4) 1[1]: (ADD 9 16) 1[1]: returned 25 0[1]: returned 25 • The first line shows SUM-SQUARES being called with arguments 3 and 4. • The second line shows that within the scope of SUMSQUARES, the function ADD is being called with arguments 9 and 16 • The third line shows the function ADD returns the value 25 • The fourth line shows the function SUM-SQUARES returns the value 25

The Lisp Compiler • (disassemble # 'square) – Shows the assembly instructions generated by

The Lisp Compiler • (disassemble # 'square) – Shows the assembly instructions generated by the compiler • Instructions depend on your OS • *. fasl files encode this information • *. lisp files are portable to multiple OS, but not *. fasl files.

Declarations • Data types of variables are not (usually) declared, e. g. – int

Declarations • Data types of variables are not (usually) declared, e. g. – int a = 0; OR Dim a as Integer • Data type of function return value is not declared • Arithmetic is generic – You can add an integer to a double-float • Compiler doesn’t warn you about data type problems • You can optionally declare data types to eliminate generic arithmetic and speed things up