diff options
author | Arun Isaac | 2022-06-27 22:45:10 +0530 |
---|---|---|
committer | Arun Isaac | 2022-06-28 10:05:06 +0530 |
commit | ebf1d504bedc39fa43ae0df179d40e411b215dc5 (patch) | |
tree | 4029f0169cc47a79a9f9a4ccfeea2e9b24f17cee | |
parent | a18bf55baad800b5a0f84680f8a2e9c211d31926 (diff) | |
download | tissue-ebf1d504bedc39fa43ae0df179d40e411b215dc5.tar.gz tissue-ebf1d504bedc39fa43ae0df179d40e411b215dc5.tar.lz tissue-ebf1d504bedc39fa43ae0df179d40e411b215dc5.zip |
document: Override write to print object slots and values.
* tissue/document.scm: Import (srfi srfi-1).
(write): New generic method.
-rw-r--r-- | tissue/document.scm | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tissue/document.scm b/tissue/document.scm index c70b18e..45de014 100644 --- a/tissue/document.scm +++ b/tissue/document.scm @@ -19,6 +19,7 @@ (define-module (tissue document) #:use-module (rnrs hashtables) #:use-module (rnrs io ports) + #:use-module (srfi srfi-1) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) #:use-module (srfi srfi-171) @@ -40,6 +41,20 @@ file-document-path read-gemtext-document)) +;; We override the default write to print object slots and values. +(define-method (write (object <object>) port) + "Write OBJECT to PORT." + (format port "#<~a ~a>" + (class-name (class-of object)) + (string-join (filter-map (lambda (slot) + (let ((slot-name (slot-definition-name slot))) + (and (slot-bound? object slot-name) + (call-with-output-string + (cut format <> "~s: ~s" + slot-name + (slot-ref object slot-name)))))) + (class-slots (class-of object)))))) + (define (date->iso-8601 date) "Convert DATE, an SRFI-19 date object, to an ISO-8601 date string." (date->string date "~4")) |