summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2022-10-09 18:58:59 +0530
committerArun Isaac2022-10-10 01:46:52 +0530
commit35c098803a217d29b0a69734ce38303a72be4084 (patch)
tree05d747b66fb145c5c677e9d32d5a310b59f78642
parentebdd54ec7a786657968bfdb0d083e87100bb8a3e (diff)
downloadtissue-35c098803a217d29b0a69734ce38303a72be4084.tar.gz
tissue-35c098803a217d29b0a69734ce38303a72be4084.tar.lz
tissue-35c098803a217d29b0a69734ce38303a72be4084.zip
tissue: Introduce define-lazy, an abstraction for lazy functions.
* tissue/tissue.scm (define-lazy): New macro.
(tissue-configuration): Define using define-lazy.
(pairify): Delete function.
(<tissue-configuration>[tissue-configuration-project,
tissue-configuration-aliases, tissue-configuration-web-css]: Force
values in getters.
-rw-r--r--tissue/tissue.scm92
1 files changed, 53 insertions, 39 deletions
diff --git a/tissue/tissue.scm b/tissue/tissue.scm
index 61ef4b8..29f31ac 100644
--- a/tissue/tissue.scm
+++ b/tissue/tissue.scm
@@ -35,15 +35,24 @@
   (make-tissue-configuration project aliases indexed-documents
                              web-css web-files)
   tissue-configuration?
-  (project tissue-configuration-project)
-  (aliases tissue-configuration-aliases)
+  (project delayed-tissue-configuration-project)
+  (aliases delayed-tissue-configuration-aliases)
   (indexed-documents delayed-tissue-configuration-indexed-documents)
-  (web-css tissue-configuration-web-css)
+  (web-css delayed-tissue-configuration-web-css)
   (web-files delayed-tissue-configuration-web-files))
 
+(define tissue-configuration-project
+  (compose force delayed-tissue-configuration-project))
+
+(define tissue-configuration-aliases
+  (compose force delayed-tissue-configuration-aliases))
+
 (define tissue-configuration-indexed-documents
   (compose force delayed-tissue-configuration-indexed-documents))
 
+(define tissue-configuration-web-css
+  (compose force delayed-tissue-configuration-web-css))
+
 (define tissue-configuration-web-files
   (compose force delayed-tissue-configuration-web-files))
 
@@ -62,46 +71,51 @@ directory they are in."
                  (string-suffix? ".gmi" filename)))
           (git-tracked-files (current-git-repository))))
 
-(define (pairify lst)
-  "Return a list of pairs of successive elements of LST. For example,
-
-(pairify (list 1 2 3 4 5 6))
-=> ((1 . 2) (3 . 4) (5 . 6))"
-  (match lst
-    (() '())
-    ((first second tail ...)
-     (cons (cons first second)
-           (pairify tail)))))
-
-(define-syntax tissue-configuration
+(define-syntax define-lazy
   (lambda (x)
+    "Define function that lazily evaluates all its arguments."
     (syntax-case x ()
-      ((_ args ...)
-       #`((lambda* (#:key project (aliases '())
-                    (indexed-documents (delay '()))
-                    web-css (web-files (delay '())))
-            "PROJECT is the name of the project. It is used in the title of the
-generated web pages, among other places.
-
-ALIASES is a list of aliases used to refer to authors in the
+      ((_ (name formal-args ...) body ...)
+       (with-syntax ((delayed-formal-args
+                      (map (lambda (formal-arg)
+                             (syntax-case formal-arg ()
+                               ((name default-value)
+                                #'(name (delay default-value)))
+                               (x #'x)))
+                           #'(formal-args ...))))
+         #`(define-syntax name
+             (lambda (x)
+               (with-ellipsis :::
+                 (syntax-case x ()
+                   ((_ args :::)
+                    #`((lambda* delayed-formal-args
+                         body ...)
+                       #,@(map (lambda (arg)
+                                 (if (keyword? (syntax->datum arg))
+                                     arg
+                                     #`(delay #,arg)))
+                               #'(args :::)))))))))))))
+
+(define-lazy (tissue-configuration #:key project (aliases '()) (indexed-documents '()) web-css (web-files '()))
+  "Construct a <tissue-configuration> object. All arguments are
+evaluated lazily.
+
+@var{project} is the name of the project. It is used in the title of
+the generated web pages, among other places.
+
+@var{aliases} is a list of aliases used to refer to authors in the
 repository. Each element is in turn a list of aliases an author goes
 by, the first of which is the canonical name of that author.
 
-INDEXED-DOCUMENTS is a list of <indexed-documents> objects
+@var{indexed-documents} is a list of @code{<indexed-document>} objects
 representing documents to index.
 
-WEB-CSS is the path to a CSS stylesheet. It is relative to the
-document root and must begin with a /. If it is #f, no stylesheet is
-used in the generated web pages.
-
-WEB-FILES is a list of <file> objects representing files to be written
-to the web output."
-            (make-tissue-configuration project aliases
-                                       indexed-documents web-css web-files))
-          #,@(append-map (match-lambda
-                           ((key . value)
-                            (if (memq (syntax->datum key)
-                                      (list #:indexed-documents #:web-files))
-                                #`(#,key (delay #,value))
-                                #`(#,key #,value))))
-                         (pairify #'(args ...))))))))
+@var{web-css} is the path to a CSS stylesheet. It is relative to the
+document root and must begin with a @code{\"/\"}. If it is @code{#f},
+no stylesheet is used in the generated web pages.
+
+@var{web-files} is a list of @code{<file>} objects representing files to be
+written to the web output.
+
+All arguments to @code{tissue-configuration} are evaluated lazily."
+   (make-tissue-configuration project aliases indexed-documents web-css web-files))