From a5f905f8c0656c5ea8ee957a5abc2e0dc7aa0193 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Tue, 28 Jun 2022 10:06:12 +0530 Subject: document: Add slot-set utility. * tissue/document.scm (slot-set): New public function. --- tissue/document.scm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tissue/document.scm') diff --git a/tissue/document.scm b/tissue/document.scm index 45de014..70a3263 100644 --- a/tissue/document.scm +++ b/tissue/document.scm @@ -28,7 +28,8 @@ #:use-module (term ansi-color) #:use-module (xapian xapian) #:use-module (tissue utils) - #:export (object->scm + #:export (slot-set + object->scm scm->object document-title @@ -41,6 +42,13 @@ file-document-path read-gemtext-document)) +(define (slot-set object slot-name value) + "Set SLOT-NAME in OBJECT to VALUE. This is a purely functional setter +that operates on a copy of OBJECT. It does not mutate OBJECT." + (let ((clone (shallow-clone object))) + (slot-set! clone slot-name value) + clone)) + ;; We override the default write to print object slots and values. (define-method (write (object ) port) "Write OBJECT to PORT." -- cgit v1.2.3