This minitutorial discusses several topics:

Invoking the HLW Stepper

The HLW stepper allows you to step through the evaluation of a S-expression one step at a time. It can, at the very least, help you comprend the Lisp evaluation model better. It can also be a very useful tool when you code seems to have a mind of it's own. :-)

Once you fall into the stepper the prompt changes to ' S-exp ->'. Where S-exp is the s-expression you are about to step.


Stepper Commands.

The stepper commands are the following.  Note that the colon is part of the
command "name".


:s       Step this form and all of its subforms (optional +ve integer arg)
:st      Step this form without stepping its subforms
:si      Step this form without stepping its arguments if it is a function call
:su      Step up out of this form without stepping its subforms
:sr      Return a value to use for this form
:sq      Quit from the current stepper level
:redo &optional <command identifier>
         Redo a previous command, identified by its number or a substring.
:get <variable> <command identifier>
         Get a command from the history list and put it in a variable.
:help    Produce this list.
:use <new form> <form to replace> &optional <command identifier> 
         Replace one form with another form in a previous command and redo the command.
:his     List the command history.


If you've used the MCL stepper.
		:s		Step Button
		:st   		Step Over Button
		:su		Go  Button  ( kind of )
		:sq		Quit Button

Stepping through an example

We'll need an example function to step through. You can step through any S-expression, like ( if t (1+ 2 ) (1+ 3) ) but that isn't very interesting. The following function is slightly more interesting.
  (defun step-me ( int num-times result )
    (cond ((= num-times 0 ) result )
          ((= num-times 1 ) result )
          (t (step-me int (1- num-times ) (+ int result )))))
Enter and evaluate this function. Next evaluate the following:
     CL-USER 6  > (step  (step-me  3 5 0 ))

If you type ':s' this will start the incremental evaluate of the function. Continuing to type ':s' will cause the next subexpression to be evaluated. When you get to the form

		(= NUM-TIMES 0 ) ->  
type ':st' to "Step Over" this form [ It's compiled anyway so there is nothing particularly interesting to be seen ].

If your code contains a break ( see the debbuger tutorial ), then you may step or enter ':st' which will likely continue evaluation until the break is reach or the evaluation is complete, whichever comes first. Unfortunately, you cannot go back into step mode after continuing from the break. See the trace minitutorial for one way to solve this "problem".

Once you get tired of stepping through step-me type ':x' and let the stepper run for the "finish line".

Looking inside the lexical scope

Now let's reinvoke the stepper again. Step twice so that the arguments are evaluated. At this point enter the command ':p S-exp'. This will cause the current expression AND the value of the S-expression you entered to be printed out. For example:

CL-USER 79 > (step (step-me 3 5 0 ))
(STEP-ME 3 5 0) -> :s
   3 -> :s
   3 
   5 -> :s
   5 
   0 -> :s
   0 
   (COND ((= NUM-TIMES 0) RESULT) ((= NUM-TIMES 1) RESULT) (T (STEP-ME INT (1- NUM-TIMES) (+ INT RESULT)))) <=> (IF (= NUM-TIMES 0) (PROGN RESULT) (IF (= NUM-TIMES 1) (PROGN RESULT) (PROGN (STEP-ME INT (1- NUM-TIMES) (+ INT RESULT)))))
   (IF (= NUM-TIMES 0) (PROGN RESULT) (IF (= NUM-TIMES 1) (PROGN RESULT) (PROGN (STEP-ME INT (1- NUM-TIMES) (+ INT RESULT))))) ->  result
0
   (IF (= NUM-TIMES 0) (PROGN RESULT) (IF (= NUM-TIMES 1) (PROGN RESULT) (PROGN (STEP-ME INT (1- NUM-TIMES) (+ INT RESULT))))) ->  (+ result 1 )
1
   (IF (= NUM-TIMES 0) (PROGN RESULT) (IF (= NUM-TIMES 1) (PROGN RESULT) (PROGN (STEP-ME INT (1- NUM-TIMES) (+ INT RESULT))))) -> :sq
:QUIT
Not exactly pretty but it is functional.

This capability can come in handy when you have stepped into an errant function and you are trying to decide what you should change to code to really do. You can try out evaluating certain S-expressions to confirm to yourself what you should have wrote in the first place.... it happens to all of us. :-)

What else can I do?

I'm sure at this point you can think of even more uses for this tool that you wished you knew about 3 Homeworks ago. To learn more about using HLW to help decipher your homework code see the debugging and tracing minitutorials.
Back to HLW and Tool Time

Last modified: by Lyman S. Taylor(lyman@cc.gatech.edu)
(c) copyright Lyman S. Taylor 1995, All rights reserved