[This goes primarly to Rob, whom I stole DBGV from, but as it's a
generally useful macro, I'm posting it here in case anyone cares]
Hi,
some time ago I stole your DBGV macro. It's nifty, except it doesn't
behave as described (ie. unlike PROGN, it eats the value of the forms
executed). I just ran into a situation where it changed the semantics of
my code, so here's a version that fixes that.
(defmacro dbgv ((&optional (where "DEBUG")
(stream *standard-output*))
&body forms)
"Execute FORMS like PROGN, but print each form and its result to the
STREAM."
(with-gensyms (result)
`(let (,result)
(progn
(format ,stream "~&DBGV: @~a:~%" ',where)
,@(loop for form in forms
collect `(progn
(setf ,result ,form)
(format t "~s = ~s~%" ',form ,result)))
,result))))
Cheers,
Maciej
In article <············@news.net.uni-c.dk>,
Maciej Katafiasz <········@gmail.com> wrote:
> [This goes primarly to Rob, whom I stole DBGV from, but as it's a
> generally useful macro, I'm posting it here in case anyone cares]
>
> Hi,
>
> some time ago I stole your DBGV macro. It's nifty, except it doesn't
> behave as described (ie. unlike PROGN, it eats the value of the forms
> executed). I just ran into a situation where it changed the semantics of
> my code, so here's a version that fixes that.
>
> (defmacro dbgv ((&optional (where "DEBUG")
> (stream *standard-output*))
> &body forms)
> "Execute FORMS like PROGN, but print each form and its result to the
> STREAM."
> (with-gensyms (result)
> `(let (,result)
> (progn
> (format ,stream "~&DBGV: @~a:~%" ',where)
> ,@(loop for form in forms
> collect `(progn
> (setf ,result ,form)
> (format t "~s = ~s~%" ',form ,result)))
> ,result))))
Note that multiple values are lost.
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Barry Margolin <······@alum.mit.edu> wrote:
> Note that multiple values are lost.
While we're comparing debugging macros, I offer the following, partly
because it does correctly support multiple values, and yields the values
to its caller (so you can take any expression e and replace it with
(SHOW e) with minimal change to the semantics of the program), but
mainly because of the awful FORMAT string.
Note that this is unlike the other macros mentioned in the thread in
that it doesn't act like PROGN. A PROGN-like version would be easy, but
I've never needed one.
(defmacro show (x)
"Debugging tool: print the expression X and its values."
(let ((tmp (gensym)))
`(let ((,tmp (multiple-value-list ,x)))
(fresh-line)
(pprint-logical-block (*standard-output* nil :per-line-prefix ";; ")
(format t
"~S = ·@_~:I~:[#<no values>~;~:*~{~S~^ ~_~}~]"
',x
,tmp))
(terpri)
(values-list ,tmp))))
-- [mdw]
Maciej Katafiasz <········@gmail.com> wrote:
+---------------
| [This goes primarly to Rob, whom I stole DBGV from, but as it's a
| generally useful macro, I'm posting it here in case anyone cares]
|
| Hi,
|
| some time ago I stole your DBGV macro. It's nifty, except it doesn't
| behave as described (ie. unlike PROGN, it eats the value of the forms
| executed).
+---------------
Where did I ever say that my DBGV acted like PROGN?
My records show that I always said exactly the opposite!!
Newsgroups: comp.lang.lisp
Date: Wed, 12 Sep 2007 21:02:50 -0500
Subject: Re: A "killer" macro
From: ····@rpw3.org (Rob Warnock)
Raymond Wiker <···@RawMBP.local> wrote:
+---------------
| Emilio Lopes <·····@gmx.net> writes:
| > Here is my take: a simple macro called `debug', which
| > prints a given *expression* followed by its value.
| ...
+---------------
...
p.s. The one from my personal toolbox, in CL:
...
I suppose I could make it return the last value like Emilio's does,
but I haven't found the need for that yet.
and:
Newsgroups: comp.lang.lisp
Date: Thu, 21 Feb 2008 23:42:17 -0600
Subject: Re: need help for a simple macro
From: ····@rpw3.org (Rob Warnock)
...
Kaz Kylheku <········@gmail.com> wrote:
+---------------
| I'd give a different name to the macro version, like CHATTY-PROGN. The
| macro version should handle multiple values from each form, in
| particular the last one. I'd make it like this:
|
| (defmacro chatty-progn (&body forms) ...[trimmed]... )
+---------------
Interesting that you added the multiple values support.
I've had a version of this in my toolbox for some years
*without* the multiple values support, and never missed it:
...
Were you perhaps thinking of Kaz's or Emilio's versions?
-Rob
-----
Rob Warnock <····@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607
Den Mon, 03 Nov 2008 21:04:24 -0600 skrev Rob Warnock:
> Where did I ever say that my DBGV acted like PROGN? My records show that
> I always said exactly the opposite!!
[snip]
> Were you perhaps thinking of Kaz's or Emilio's versions?
Good question. I went with the docstring (the same as in the version I
posted), and then assumed it came from you together with the rest of the
macro, which I have annotated as "stolen from Rob". It's quite possible
that I added the docstring myself without reading it properly and then
forgot about it, having thus confused the future myself. Oh well.
Cheers,
Maciej
PS. Thanks for pointing out the multiple values support thing in Kaz's
version, I guess I'll add that too.