Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp...

14
Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp Development in the IDE

Transcript of Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp...

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

Allegro CL Certification Program

Lisp Programming Series Level I

Session 1.1.4

Basic Lisp Development in the IDE

Page 2: 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

• The windows you get:– Menu bar across the top– Debug window– Untitled Edit window– Form window – Inspect window

Page 3: Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp Development in the IDE.

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

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

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

Page 5: Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp Development in the IDE.

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

Page 6: Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp Development in the IDE.

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):

Page 7: Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp Development in the IDE.

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

Page 8: Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp Development in the IDE.

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

Page 9: Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp Development in the IDE.

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

Page 10: Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp Development in the IDE.

How to Set a Breakpoint

(defun foo (x)

(declare (optimize (debug 3)))

(let ((y (cons 2 3)))

(BREAK)

(cons x y)))

Page 11: Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp Development in the IDE.

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)

Page 12: Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp Development in the IDE.

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 SUM-SQUARES, 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

Page 13: Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp Development in the IDE.

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.

Page 14: Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.4 Basic Lisp Development in the IDE.

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