From: Mark Carter
Subject: SBCL debugging
Date: 
Message-ID: <48a9bfe8$0$2508$da0feed9@news.zen.co.uk>
I'm new to Lisp, and I'd like to get to grips with the debugger.

I have written a function:

(defun yahoo (epic)
   (let (url contents fields price-string price)
     (setf url "http://uk.finance.yahoo.com/d/quotes.csv?s=")
     (str+! url epic)
     (str+! url "&f=sl1d1t1c1ohgv&e=.csv")
     (setf contents (http-get url))
     (setf fields (split-sequence #\, contents))
     (setf price-string (second fields))
     (setf price (read-from-string price-string))
     price))

Now, this basically does the right thing if you supply it with a valid 
epic code.

Let's just supply it with a known problem to see what happens

(yahoo "ABBYA.L")

I get

debugger invoked on a TYPE-ERROR: The value NIL is not of type STRING.

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
   0: [ABORT] Exit debugger, returning to top level.

(READ-FROM-STRING NIL)[:EXTERNAL]


Well, actually I know why it's gone wrong - but let's pretend I didn't. 
If I type
back 5
I get

0: (READ-FROM-STRING NIL)[:EXTERNAL]
1: (YAHOO "ABBYA.L")
2: (SB-INT:SIMPLE-EVAL-IN-LEXENV (YAHOO "ABBYA.L") #<NULL-LEXENV>)
3: (INTERACTIVE-EVAL (YAHOO "ABBYA.L"))
4: (SB-IMPL::REPL-FUN NIL)


Ideally, I would like to be able to see what values are in the variables 
url, contents, and fields. I can't see how I do this, though. I figured 
I wanted something like
0] frame 1
(YAHOO "ABBYA.L")

But when I type l to list the local variables, all I get is
SB-DEBUG::ARG-0  =  "ABBYA.L"


Any ideas?

From: Marco Antoniotti
Subject: Re: SBCL debugging
Date: 
Message-ID: <50ebbd41-353a-4e28-8fb6-f146e3acba59@f63g2000hsf.googlegroups.com>
On Aug 18, 2:31 pm, Mark Carter <····@privacy.net> wrote:
> I'm new to Lisp, and I'd like to get to grips with the debugger.
>
> I have written a function:
>
> (defun yahoo (epic)
>    (let (url contents fields price-string price)
>      (setf url "http://uk.finance.yahoo.com/d/quotes.csv?s=")
>      (str+! url epic)
>      (str+! url "&f=sl1d1t1c1ohgv&e=.csv")
>      (setf contents (http-get url))
>      (setf fields (split-sequence #\, contents))
>      (setf price-string (second fields))
>      (setf price (read-from-string price-string))
>      price))

Too many SETFs and STR+! has unknown behavior (at least to me).  Are
you sure the following does not work?  (Note that HTTP-GET is still
unknown)

(defun yahoo (epic)
   (let* ((url  "http://uk.finance.yahoo.com/d/quotes.csv?s=") ;
Literal object!!!
          (query-url (concatenate 'string
                                  epic
                                  "&f=sl1d1t1c1ohgv&e=.csv"))
          (contents (http-get query-url))
          (price-string (second (split-sequence #\, contents)))
          )
     (read-from-string price-string)))


Cheers
--
Marco
From: Mark Carter
Subject: Re: SBCL debugging
Date: 
Message-ID: <48a9d23b$0$2525$da0feed9@news.zen.co.uk>
Marco Antoniotti wrote:
> On Aug 18, 2:31 pm, Mark Carter <····@privacy.net> wrote:
>> I'm new to Lisp, and I'd like to get to grips with the debugger.
>>
>> I have written a function:
>>
>> (defun yahoo (epic)
>>    (let (url contents fields price-string price)
>>      (setf url "http://uk.finance.yahoo.com/d/quotes.csv?s=")
>>      (str+! url epic)
>>      (str+! url "&f=sl1d1t1c1ohgv&e=.csv")
>>      (setf contents (http-get url))
>>      (setf fields (split-sequence #\, contents))
>>      (setf price-string (second fields))
>>      (setf price (read-from-string price-string))
>>      price))
> 
> Too many SETFs and STR+! has unknown behavior (at least to me).  Are
> you sure the following does not work?  (Note that HTTP-GET is still
> unknown)
> 
> (defun yahoo (epic)
>    (let* ((url  "http://uk.finance.yahoo.com/d/quotes.csv?s=") ;
> Literal object!!!
>           (query-url (concatenate 'string
>                                   epic
>                                   "&f=sl1d1t1c1ohgv&e=.csv"))
>           (contents (http-get query-url))
>           (price-string (second (split-sequence #\, contents)))
>           )
>      (read-from-string price-string)))
> 
> 

Well, it doesn't work if I supply a random epic code. There's a small 
bug in your code: it should be
	(query-url (concatenate 'string url ...
instead of
	(query-url (concatenate 'string ...
And in a way, the point of the exercise is to try to find these kinds of 
errors by being able to see what the values are.

I see from the documentation from SBCL that there is a DEBUG command, 
but when I type
	(debug 2)
I get
	debugger invoked on a UNDEFINED-FUNCTION: The function DEBUG is undefined.
From: John Thingstad
Subject: Re: SBCL debugging
Date: 
Message-ID: <op.uf3mm1klut4oq5@pandora.alfanett.no>
P� Mon, 18 Aug 2008 21:49:15 +0200, skrev Mark Carter <··@privacy.net>:

>
> I see from the documentation from SBCL that there is a DEBUG command,  
> but when I type
> 	(debug 2)
> I get
> 	debugger invoked on a UNDEFINED-FUNCTION: The function DEBUG is  
> undefined.
>

There is no debug command. There is a debug declaration.

(declare (optimize (debug 3))

The options are safety, speed, size and debug which can have values from  
0-3.  0 being lowest priority and 3 being the highest.

(declare (optimize debug)) would set debug to 3
It has the effect of turning off tail recursion and register optimisations  
and a number of other optimisations.
The register optimisations is the reason the name got 'lost'.
Declarations have to be placed right after the comment section of the  
function.

--------------
John Thingstad
From: Brian
Subject: Re: SBCL debugging
Date: 
Message-ID: <e7ce4fc3-d0a7-4a4d-818e-ab0b029cd055@e39g2000hsf.googlegroups.com>
On Aug 18, 1:31 pm, Mark Carter <····@privacy.net> wrote:
> I'm new to Lisp, and I'd like to get to grips with the debugger.
>
> I have written a function:
>
> (defun yahoo (epic)
>    (let (url contents fields price-string price)
>      (setf url "http://uk.finance.yahoo.com/d/quotes.csv?s=")
>      (str+! url epic)
>      (str+! url "&f=sl1d1t1c1ohgv&e=.csv")
>      (setf contents (http-get url))
>      (setf fields (split-sequence #\, contents))
>      (setf price-string (second fields))
>      (setf price (read-from-string price-string))
>      price))
>
> Now, this basically does the right thing if you supply it with a valid
> epic code.
>
> Let's just supply it with a known problem to see what happens
>
> (yahoo "ABBYA.L")
>
> I get
>
> debugger invoked on a TYPE-ERROR: The value NIL is not of type STRING.
>
> Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
>
> restarts (invokable by number or by possibly-abbreviated name):
>    0: [ABORT] Exit debugger, returning to top level.
>
> (READ-FROM-STRING NIL)[:EXTERNAL]
>
> Well, actually I know why it's gone wrong - but let's pretend I didn't.
> If I type
> back 5
> I get
>
> 0: (READ-FROM-STRING NIL)[:EXTERNAL]
> 1: (YAHOO "ABBYA.L")
> 2: (SB-INT:SIMPLE-EVAL-IN-LEXENV (YAHOO "ABBYA.L") #<NULL-LEXENV>)
> 3: (INTERACTIVE-EVAL (YAHOO "ABBYA.L"))
> 4: (SB-IMPL::REPL-FUN NIL)
>
> Ideally, I would like to be able to see what values are in the variables
> url, contents, and fields. I can't see how I do this, though. I figured
> I wanted something like
> 0] frame 1
> (YAHOO "ABBYA.L")
>
> But when I type l to list the local variables, all I get is
> SB-DEBUG::ARG-0  =  "ABBYA.L"
>
> Any ideas?
Throw in a (declare (optimize debug)) before the let.

In SBCL 1.0.19, the L command in the debugger will then show the names
and the values of the local variables (if they aren't optimized away,
which they shouldn't be here).
From: Mark Carter
Subject: Re: SBCL debugging
Date: 
Message-ID: <48a9d663$0$2521$da0feed9@news.zen.co.uk>
Brian wrote:
> On Aug 18, 1:31 pm, Mark Carter <····@privacy.net> wrote:

> Throw in a (declare (optimize debug)) before the let.
> 
> In SBCL 1.0.19, the L command in the debugger will then show the names
> and the values of the local variables (if they aren't optimized away,
> which they shouldn't be here).

Aaah! Many thanks. That does the trick!

Now I have

0]
fram 1
(YAHOO "foo")
1] l
CONTENTS  =  ""
EPIC  =  "foo"
FIELDS  =  ("")
PRICE-STRING  =  NIL
URL  = 
"http://uk.finance.yahoo.com/d/quotes.csv?s=foo&f=sl1d1t1c1ohgv&e=.csv"


Very nice. I hear that Lisp has a facility for altering stuff 
dynamically within frames. So suppose I'm in frame 1. If type
	source
I get
	(READ-FROM-STRING PRICE-STRING)
Is there a way I can set price-string to a value like "blah,12" and 
continue on calling read-from-string?
From: Brian
Subject: Re: SBCL debugging
Date: 
Message-ID: <2715e278-633a-4cba-b6d4-eb7c40266e35@e39g2000hsf.googlegroups.com>
On Aug 18, 3:06 pm, Mark Carter <····@privacy.net> wrote:
> Brian wrote:
> > On Aug 18, 1:31 pm, Mark Carter <····@privacy.net> wrote:
> > Throw in a (declare (optimize debug)) before the let.
>
> > In SBCL 1.0.19, the L command in the debugger will then show the names
> > and the values of the local variables (if they aren't optimized away,
> > which they shouldn't be here).
>
> Aaah! Many thanks. That does the trick!
>
> Now I have
>
> 0]
> fram 1
> (YAHOO "foo")
> 1] l
> CONTENTS  =  ""
> EPIC  =  "foo"
> FIELDS  =  ("")
> PRICE-STRING  =  NIL
> URL  =
> "http://uk.finance.yahoo.com/d/quotes.csv?s=foo&f=sl1d1t1c1ohgv&e=.csv"
>
> Very nice. I hear that Lisp has a facility for altering stuff
> dynamically within frames. So suppose I'm in frame 1. If type
>         source
> I get
>         (READ-FROM-STRING PRICE-STRING)
> Is there a way I can set price-string to a value like "blah,12" and
> continue on calling read-from-string?
You should be able to go down frames until PRICE-STRING is a local
variable, then use (setf (sb-debug:var 'price-string) "blah,12") to
set the local variable, do RESTART-FRAME.

(side note, on SBCL 1.0.19 on windows, Your Kitten of Death awaits
when you do RESTART-FRAME)
From: MasterZiv
Subject: Re: SBCL debugging
Date: 
Message-ID: <b43488b4-2886-48af-91a1-fb1f5af306cb@e39g2000hsf.googlegroups.com>
On Aug 18, 11:40 pm, Brian <··············@gmail.com> wrote:

> Throw in a (declare (optimize debug)) before the let.
>
> In SBCL 1.0.19, the L command in the debugger will then show the names
> and the values of the local variables (if they aren't optimized away,
> which they shouldn't be here).

Can I do something with same effect as
(declare (optimize debug))
instance-wise ? I mean, can I apply this to all functions in a package
or in a number of packages without changing the code back and forth ?
From: Rainer Joswig
Subject: Re: SBCL debugging
Date: 
Message-ID: <joswig-2BE986.09040319082008@news-europe.giganews.com>
In article 
<····································@e39g2000hsf.googlegroups.com>,
 MasterZiv <·········@gmail.com> wrote:

> On Aug 18, 11:40�pm, Brian <··············@gmail.com> wrote:
> 
> > Throw in a (declare (optimize debug)) before the let.
> >
> > In SBCL 1.0.19, the L command in the debugger will then show the names
> > and the values of the local variables (if they aren't optimized away,
> > which they shouldn't be here).
> 
> Can I do something with same effect as
> (declare (optimize debug))
> instance-wise ? I mean, can I apply this to all functions in a package
> or in a number of packages without changing the code back and forth ?

You have to recompile the functions.

(defun foo ()
  (declare (optimize (speed 3)))
  ...)

or even

(defun foo ()
  ...
  (locally (declare (optimize (speed 3)))
     ...)
  ...)

A code 'body' usually allows declarations at the top.
LOCALLY allows a new local scope for declarations.

-- 
http://lispm.dyndns.org/
From: Pascal J. Bourguignon
Subject: Re: SBCL debugging
Date: 
Message-ID: <87tzdhh3jw.fsf@hubble.informatimago.com>
MasterZiv <·········@gmail.com> writes:

> On Aug 18, 11:40�pm, Brian <··············@gmail.com> wrote:
>
>> Throw in a (declare (optimize debug)) before the let.
>>
>> In SBCL 1.0.19, the L command in the debugger will then show the names
>> and the values of the local variables (if they aren't optimized away,
>> which they shouldn't be here).
>
> Can I do something with same effect as
> (declare (optimize debug))
> instance-wise ? I mean, can I apply this to all functions in a package
> or in a number of packages without changing the code back and forth ?

DECLAIM it instead! (at the toplevel).

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.
From: Tobias C. Rittweiler
Subject: Re: SBCL debugging
Date: 
Message-ID: <87pro5mo6y.fsf@freebits.de>
MasterZiv <·········@gmail.com> writes:

> On Aug 18, 11:40�pm, Brian <··············@gmail.com> wrote:
>
> > Throw in a (declare (optimize debug)) before the let.
> >
> > In SBCL 1.0.19, the L command in the debugger will then show the names
> > and the values of the local variables (if they aren't optimized away,
> > which they shouldn't be here).
>
> Can I do something with same effect as
> (declare (optimize debug))
> instance-wise ? I mean, can I apply this to all functions in a package
> or in a number of packages without changing the code back and forth ?

You can use `C-u C-c C-c' in reasonably recent versions of Slime to
compile the toplevel at point with maximum debug. (Only supported by the
SBCL backend at the moment.)

  -T.