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

the debug macro

36 views
Skip to first unread message

Madhu

unread,
Apr 15, 2023, 11:24:05 AM4/15/23
to
I recently had to reinvent this, but I'm sure I've seen a version of it
on cll decades ago. Anyone remember which poster or post? I'm
interested to see how it was described.

```
(defmacro debug (&rest syms)
(let ((leader (if (stringp (car syms)) (pop syms) "DEBUG")))
(let ((format-string (format nil "~A: ~{~A=~~S~^, ~}~~&" leader syms)))
`(format t ,format-string ,@syms))))
```

The best docstring I could come up with is:

"\(DEBUG [\"DEBUG-MSG\"] [ITEMS...] \) prints DEBUG-MSG: [ITEM=VAL ...]
on standard output"


A slight advantage may be gleaned if the string and arguments to DEBUG
are treated as such:

```
(defmacro debug (&rest syms-and-strings)
(let* ((args nil)
(fmt-string
(with-output-to-string (stream)
(loop for (c . rest) on syms-and-strings do
(typecase c
(string (princ c stream))
((or (and symbol (not keyword)) (not atom))
(push c args)
(princ c stream)
(princ "=~S" stream))
(otherwise (prin1 c stream)))
(princ (if (endp rest) #\Newline #\Space) stream)))))
`(format t ,fmt-string ,@(nreverse args))))
```

But then it loses some of the declarative conciseness

Madhu

unread,
May 25, 2023, 6:18:40 AM5/25/23
to

* In <m335512...@leonis4.robolove.meer.net> :
I Wrote on Sat, 15 Apr 2023 20:54:19 +0530:

> I recently had to reinvent this, but I'm sure I've seen a version of it
> on cll decades ago. Anyone remember which poster or post? I'm
> interested to see how it was described.

I found this one now, https://github.com/danlentz/printv
0 new messages