From 35c098803a217d29b0a69734ce38303a72be4084 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sun, 9 Oct 2022 18:58:59 +0530 Subject: 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-project, tissue-configuration-aliases, tissue-configuration-web-css]: Force values in getters. --- tissue/tissue.scm | 92 ++++++++++++++++++++++++++++++++----------------------- 1 file 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 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 objects +@var{indexed-documents} is a list of @code{} 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 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{} 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)) -- cgit v1.2.3