Subject: Re: A "killer" macro
From: rpw3@rpw3.org (Rob Warnock)
Date: Wed, 12 Sep 2007 21:02:50 -0500
Newsgroups: comp.lang.lisp
Message-ID: <74idnTlKL5jXB3XbnZ2dnUVZ_vyinZ2d@speakeasy.net>
Raymond Wiker  <raw@RawMBP.local> wrote:
+---------------
| Emilio Lopes <eclig@gmx.net> writes:
| > Here is my take: a simple macro called `debug', which
| > prints a given *expression* followed by its value.
...
| > Here is the macro definition [in Scheme]:
| >    (define-syntax debug
| >      (syntax-rules () ...))
| >        ((_ expr)
| >         (let ((literal (quote expr))
| >               (value expr))
| >           (display "### ")
| >           (display literal)
| >           (display ": ")
| >           (write value)
| >           (newline)
| >           value))
| >        ((_ expr expr1 ...)
| >         (begin
| >           (debug expr)
| >           (debug expr1 ...)))))
...
| Not a convincing example of the power of (Lisp) macros;
| even C++ can do this: ...
| #define DEBUG(a) (std::cerr << "### " << #a << ": " << (a) << std::endl, a)
+---------------

*BZZZTT!!* Your C++ macro only takes *one* expression;
his takes an *arbitrary* number of expressions in a
single call of the macro!! Let's see you do *that* in C++!!


-Rob

p.s. The one from my personal toolbox, in CL:

    > (defmacro dbgv ((&optional (where "Some Unknown Location..."))
		       &rest forms)
	`(progn
	   (format t "~&DBGV: @~a:~%" ',where)
	   ,@(loop for form in forms
	       collect `(format t "~s = ~s~%" ',form ,form))))

    DBGV
    > (dbgv (the-repl) (+ 1 2) (expt 2 100) (strcat "foo" "bar"))

    DBGV: @THE-REPL:
    (+ 1 2) = 3
    (EXPT 2 100) = 1267650600228229401496703205376
    (STRCAT "foo" "bar") = "foobar"
    NIL
    > 

I suspose I could make it return the last value like Emilio's does,
but I haven't found the need for that yet.

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607