Skip to content

Instantly share code, notes, and snippets.

@bowbow99
Created October 5, 2010 03:13
Show Gist options
  • Select an option

  • Save bowbow99/610925 to your computer and use it in GitHub Desktop.

Select an option

Save bowbow99/610925 to your computer and use it in GitHub Desktop.
#xyzzy で structure を #S(...) で出力。スロット毎に改行+インデント。
#+xyzzy
(defun print-structure-sharp-s-aligned (obj stream n)
(assert (si:*structurep obj))
(let ((def (si:*structure-definition obj)))
(format stream "#S(~S" (si:*structure-definition-name def))
(let ((indent (1+ (si:*stream-column stream))))
(dotimes (i (si:*structure-definition-nslots def))
(unless (= i 0)
(terpri stream))
(format stream " ~VT~S ~S"
(if (= i 0) 0 indent)
(si:*structure-definition-slot-description def i)
(si:*index-slot-value obj i)))
(format stream ")"))))
;;; 試してみる
(defstruct (something
(:print-function print-structure-sharp-s-aligned))
foo bar baz)
=> #<structure-definition: something>
(print-structure-sharp-s-aligned
(make-something :foo 33 :bar (make-hash-table) :baz (cons nil nil))
*standard-output*
1)
#S(something :foo 33
:bar #<hashtable 82317844>
:baz (nil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment