Skip to content

Instantly share code, notes, and snippets.

@bowbow99
Forked from youz/debug-print.lisp
Created October 18, 2010 16:21
Show Gist options
  • Save bowbow99/632516 to your computer and use it in GitHub Desktop.
Save bowbow99/632516 to your computer and use it in GitHub Desktop.
;;; ref. http://practical-scheme.net/gauche/man/gauche-refj_16.html#SEC18
(defmacro debug-print (form stream)
`(progn
(format t "~&#?=~S:~S:~S~%"
,(or *load-pathname*
(when (buffer-stream-p stream)
(buffer-name (buffer-stream-buffer stream)))
stream)
,(si:*stream-line-number stream)
',form)
(let ((#1=#:values (multiple-value-list ,form)))
(format t "~&#?- ~{~S~%~^#?+ ~}" #1#)
(values-list #1#))))
(set-dispatch-macro-character #\# #\?
#'(lambda (s c n)
(declare (ignore c n))
(read-char s t)
`(debug-print ,(read s t nil t) ,s)))
@bowbow99
Copy link
Author

read 元のファイル名 or バッファ名 or ストリームと行番号も出力させてみた。

@bowbow99
Copy link
Author

form が何か出力した時のために #?=... と #?- の前で fresh-line しておいた。

(progn #?=(progn (print "foo") (values 'a 'b 'c)))
#?="*scratch*":43:(progn (print "foo") (values 'a 'b 'c))

"foo" 
#?-    a
#?+    b
#?+    c
=> a
=> b
=> c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment