From ebf1d504bedc39fa43ae0df179d40e411b215dc5 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 27 Jun 2022 22:45:10 +0530 Subject: document: Override write to print object slots and values. * tissue/document.scm: Import (srfi srfi-1). (write): New generic method. --- tissue/document.scm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tissue/document.scm') 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 ) 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")) -- cgit v1.2.3