Created
October 5, 2010 03:13
-
-
Save bowbow99/610925 to your computer and use it in GitHub Desktop.
#xyzzy で structure を #S(...) で出力。スロット毎に改行+インデント。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #+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 ")")))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; 試してみる | |
| (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