Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to step through code in common lisp?

1,273 views
Skip to first unread message

Yves S. Garret

unread,
Sep 30, 2012, 6:56:41 PM9/30/12
to
Hello,

I went through the following tutorial in the bottom link:
http://www.cliki.net/TutorialClispDebugger

It's all well and good, but I remember in my gdb days where I could step through the code and examine all of the variables as I went through each function. Maybe I missed it in the above tutorial, but how could I do this?

Benjamin Kreuter

unread,
Sep 30, 2012, 9:50:42 PM9/30/12
to
There is "step" in the standard. I use sbcl and not clisp, but just as
an example:

* (declaim (optimize (debug 3) (speed 0)))

* (defun fact (x) (if (= x 1) 1 (* x (fact (1- x)))))

FACT
* (step (fact 5))
; Evaluating call:
; (FACT 5)
; With arguments:
; 5

1] step
; Evaluating call:
; (- X 1)
; With unknown arguments

0] next
; Evaluating call:
; (FACT (1- X))
; With arguments:
; 4

1] list-locals
X = 5

Check the clisp documentation for information about how to do it
there...

-- Ben



--
Benjamin R Kreuter
UVA Computer Science
brk...@virginia.edu
KK4FJZ

--

"If large numbers of people are interested in freedom of speech, there
will be freedom of speech, even if the law forbids it; if public
opinion is sluggish, inconvenient minorities will be persecuted, even
if laws exist to protect them." - George Orwell

Nils M Holm

unread,
Oct 1, 2012, 1:56:27 AM10/1/12
to
Yves S. Garret <yoursurr...@gmail.com> wrote:
> It's all well and good, but I remember in my gdb days where I
> could step through the code and examine all of the variables as I
> went through each function. Maybe I missed it in the above tutorial,
> but how could I do this?

Never underestimate the value of a few strategic PRINT expressions.
While a debugger is certainly useful, I rarely find myself in a
position where I actually need one.

--
Nils M Holm < n m h @ t 3 x . o r g > www.t3x.org

Pascal J. Bourguignon

unread,
Oct 1, 2012, 6:54:01 AM10/1/12
to
Benjamin Kreuter <brk...@virginia.edu> writes:

> On Sun, 30 Sep 2012 15:56:41 -0700 (PDT)
> "Yves S. Garret" <yoursurr...@gmail.com> wrote:
>
>> Hello,
>>
>> I went through the following tutorial in the bottom link:
>> http://www.cliki.net/TutorialClispDebugger
>>
>> It's all well and good, but I remember in my gdb days where I could
>> step through the code and examine all of the variables as I went
>> through each function. Maybe I missed it in the above tutorial, but
>> how could I do this?
>
> There is "step" in the standard. I use sbcl and not clisp, but just as
> an example:

Unfortunately, ccl doesn't implement CL:STEP.
Fortunately, there's an implementation independant cl-stepper in:
https://gitorious.org/com-informatimago/com-informatimago/trees/master/common-lisp/lisp


cl-user> (ql:quickload :com.informatimago.common-lisp.lisp.stepper)
To load "com.informatimago.common-lisp.lisp.stepper":
Load 1 ASDF system:
com.informatimago.common-lisp.lisp.stepper
; Loading "com.informatimago.common-lisp.lisp.stepper"
[package com.informatimago.common-lisp.lisp.stepper.internal]
[package com.informatimago.common-lisp.lisp.stepper].
......
(:com.informatimago.common-lisp.lisp.stepper)
cl-user> (defpackage :test (:use :cl-stepper))
#<package "TEST">
cl-user> (in-package :test)
#<package "TEST">
test> (defun fact (x) (if (= x 1) 1 (* x (fact (1- x)))))
fact
test> (step (fact 5))
(Will evaluate (fact 5)
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s
Will evaluate (fact 5)
(Will evaluate 5
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s

(--> 5))
(Entering function fact
(Bind x to 5)
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s

(Will evaluate (if (= x 1) 1 (* x (fact #)))
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s
Will evaluate (if (= x 1) 1 (* x (fact #)))
(Will evaluate (= x 1)
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s
Will evaluate (= x 1)
(Will evaluate x
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s

(x ==> 5))
(Will evaluate 1
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s

(--> 1))
Evaluation of (= x 1) returned one result ==> nil)
(Will evaluate (* x (fact (1- x)))
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s
Will evaluate (* x (fact (1- x)))
(Will evaluate x
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s

(x ==> 5))
(Will evaluate (fact (1- x))
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s
Will evaluate (fact (1- x))
(Will evaluate (1- x)
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s
Will evaluate (1- x)
(Will evaluate x
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s

(x ==> 5))
Evaluation of (1- x) returned one result ==> 4)
(Entering function fact
(Bind x to 4)
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s

(Will evaluate (if (= x 1) 1 (* x (fact #)))
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s
Will evaluate (if (= x 1) 1 (* x (fact #)))
(Will evaluate (= x 1)
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s
Will evaluate (= x 1)
(Will evaluate x
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s

(x ==> 4))
(Will evaluate 1
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s

(--> 1))
Evaluation of (= x 1) returned one result ==> nil)
(Will evaluate (* x (fact (1- x)))
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s
Will evaluate (* x (fact (1- x)))
(Will evaluate x
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s

(x ==> 4))
(Will evaluate (fact (1- x))
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s
Will evaluate (fact (1- x))
(Will evaluate (1- x)
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s
Will evaluate (1- x)
(Will evaluate x
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s

(x ==> 4))
Evaluation of (1- x) returned one result ==> 3)
(Entering function fact
(Bind x to 3)
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?s

(Will evaluate (if (= x 1) 1 (* x (fact #)))
Step Into (s, si, RET), Step over (so), Trace (t), Function (f), Run (r), Debugger (d), Abort (a, q)?t
Will evaluate (if (= x 1) 1 (* x (fact #)))
(Will evaluate (= x 1)
(x ==> 3)
Evaluation of (= x 1) returned one result ==> nil)
(Will evaluate (* x (fact (1- x)))
(x ==> 3)
(Will evaluate (fact (1- x))
(Will evaluate (1- x)
(x ==> 3)
Evaluation of (1- x) returned one result ==> 2)
(Entering function fact
(Bind x to 2)
(Will evaluate (if (= x 1) 1 (* x (fact #)))
(Will evaluate (= x 1)
(x ==> 2)
Evaluation of (= x 1) returned one result ==> nil)
(Will evaluate (* x (fact (1- x)))
(x ==> 2)
(Will evaluate (fact (1- x))
(Will evaluate (1- x)
(x ==> 2)
Evaluation of (1- x) returned one result ==> 1)
(Entering function fact
(Bind x to 1)
(Will evaluate (if (= x 1) 1 (* x (fact #)))
(Will evaluate (= x 1)
(x ==> 1)
Evaluation of (= x 1) returned one result ==> t)
Evaluation of (if (= x 1) 1 (* x (fact #))) returned one result ==> 1)
Exiting function fact returned one result ==> 1)
Evaluation of (fact (1- x)) returned one result ==> 1)
Evaluation of (* x (fact (1- x))) returned one result ==> 2)
Evaluation of (if (= x 1) 1 (* x (fact #))) returned one result ==> 2)
Exiting function fact returned one result ==> 2)
Evaluation of (fact (1- x)) returned one result ==> 2)
Evaluation of (* x (fact (1- x))) returned one result ==> 6)
Evaluation of (if (= x 1) 1 (* x (fact #))) returned one result ==> 6)
Exiting function fact returned one result ==> 6)
Evaluation of (fact (1- x)) returned one result ==> 6)
Evaluation of (* x (fact (1- x))) returned one result ==> 24)
Evaluation of (if (= x 1) 1 (* x (fact #))) returned one result ==> 24)
Exiting function fact returned one result ==> 24)
Evaluation of (fact (1- x)) returned one result ==> 24)
Evaluation of (* x (fact (1- x))) returned one result ==> 120)
Evaluation of (if (= x 1) 1 (* x (fact #))) returned one result ==> 120)
Exiting function fact returned one result ==> 120)
Evaluation of (fact 5) returned one result ==> 120)
120
test>

--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.

Yves S. Garret

unread,
Oct 1, 2012, 10:58:08 AM10/1/12
to
informatimago, how would you actually load those libraries? I got the repository for that:

$ git clone git://gitorious.org/com-informatimago/com-informatimago.git
Cloning into 'com-informatimago'...
remote: Counting objects: 3029, done.
remote: Compressing objects: 100% (2070/2070), done.
Receiving objectsremote: Total 3029 (delta 2154), reused 1450 (delta 916)
Receiving objects: 100% (3029/3029), 2.87 MiB | 593 KiB/s, done.
Resolving deltas: 100% (2154/2154), done.
Checking out files: 100% (421/421), done.

Now, how can I get common lisp to "see" this library so that I can use it?

Pascal J. Bourguignon

unread,
Oct 1, 2012, 11:44:39 AM10/1/12
to
"Yves S. Garret" <yoursurr...@gmail.com> writes:

> informatimago, how would you actually load those libraries? I got the repository for that:

I told you:

>> cl-user> (ql:quickload :com.informatimago.common-lisp.lisp.stepper)


> $ git clone git://gitorious.org/com-informatimago/com-informatimago.git
> Cloning into 'com-informatimago'...
> remote: Counting objects: 3029, done.
> remote: Compressing objects: 100% (2070/2070), done.
> Receiving objectsremote: Total 3029 (delta 2154), reused 1450 (delta 916)
> Receiving objects: 100% (3029/3029), 2.87 MiB | 593 KiB/s, done.
> Resolving deltas: 100% (2154/2154), done.
> Checking out files: 100% (421/421), done.
>
> Now, how can I get common lisp to "see" this library so that I can use it?

Now, since I may commit new features or bug corrections at any time, and
since quicklisp only updates once a month, you may want to clone the
repository directly until next month. In that case, do it in
~/quicklisp/local-projects and keep using the quickload form above.

Yves S. Garret

unread,
Oct 1, 2012, 2:11:01 PM10/1/12
to
Right, but how does quickload know where those libraries are located?

This is what I tried and the result that I got:


[1]> (ql:quickload :com.informatimago.common-lisp.lisp.stepper)

*** - READ from #<INPUT CONCATENATED-STREAM #<INPUT STRING-INPUT-STREAM> #<IO TERMINAL-STREAM>>: there is no package with name "QL"
The following restarts are available:
ABORT :R1 Abort main loop
Break 1 [2]>


I don't really understand how to do this.

Yves S. Garret

unread,
Oct 1, 2012, 2:21:06 PM10/1/12
to
Durr, quicklisp, just got it installed, am playing with it now. Will get back to you on my progress.

Pascal J. Bourguignon

unread,
Oct 1, 2012, 2:44:52 PM10/1/12
to
"Yves S. Garret" <yoursurr...@gmail.com> writes:

> Right, but how does quickload know where those libraries are located?

Yes, it does.


> This is what I tried and the result that I got:
>
>
> [1]> (ql:quickload :com.informatimago.common-lisp.lisp.stepper)
>
> *** - READ from #<INPUT CONCATENATED-STREAM #<INPUT STRING-INPUT-STREAM> #<IO TERMINAL-STREAM>>: there is no package with name "QL"
> The following restarts are available:
> ABORT :R1 Abort main loop
> Break 1 [2]>
>
>
> I don't really understand how to do this.

http://quicklisp.org

Yves S. Garret

unread,
Oct 2, 2012, 8:53:28 AM10/2/12
to
Hi informatimago, I tried what you showed me to do and it worked wonderfully. There is one problem though, after I finished stepping through the program, I was stuck at this:

test>

I couldn't do (quit) or use my declared functions in .clisprc.lisp (located in my home directory), how do I get out of this state?

Pascal J. Bourguignon

unread,
Oct 2, 2012, 9:15:11 AM10/2/12
to
The prompt in slime gives the name (or part of the name) of the current
package.

In clisp, the COMMON-LISP-USER package uses the EXT package which
exports a QUIT function.

So you have the choice between changing the current package to a package
where "quit" would be read as the symbol EXT:QUIT, or calling that
directly:

test> (ext:quit)

or:

test> (in-package :cl-user)
cl-user> (quit)

Pascal J. Bourguignon

unread,
Oct 2, 2012, 9:18:40 AM10/2/12
to
"Pascal J. Bourguignon" <p...@informatimago.com> writes:

> "Yves S. Garret" <yoursurr...@gmail.com> writes:
>
>> Hi informatimago, I tried what you showed me to do and it worked
>> wonderfully. There is one problem though, after I finished stepping
>> through the program, I was stuck at this:
>>
>> test>
>>
>> I couldn't do (quit) or use my declared functions in .clisprc.lisp
>> (located in my home directory), how do I get out of this state?
>
> The prompt in slime gives the name (or part of the name) of the current
> package.
>
> In clisp, the COMMON-LISP-USER package uses the EXT package which
> exports a QUIT function.
>
> So you have the choice between changing the current package to a package
> where "quit" would be read as the symbol EXT:QUIT, or calling that
> directly:
>
> test> (ext:quit)
>
> or:
>
> test> (in-package :cl-user)
> cl-user> (quit)

or of couse, you can use the package where the wanted symbols are, or
import them:

test> (use-package :ext)
test> (quit)

or:
test> (import 'ext:quit)
test> (quit)
0 new messages