Madhu
unread,Apr 15, 2023, 11:24:05 AM4/15/23You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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