commit 8cd1f7f9b6972a3a413d3050db8de16c4ff317ba
parent 9a729139b93c5b103251138fbd92a6642a39599a
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 27 Jul 2025 22:55:13 +0100
rename and extract cons-tag -> lib.prepend
Diffstat:
3 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/Makefile b/Makefile
@@ -2,7 +2,7 @@ FENNEL?=fennel
PREFIX?=/usr/local
NAME?=cripslock
-MODULES=main.fnl textile.fnl site.fnl html.fnl
+MODULES=main.fnl textile.fnl site.fnl html.fnl lib.fnl
%.lua : %.fnl
$(FENNEL) --compile $< > $@
diff --git a/lib.fnl b/lib.fnl
@@ -0,0 +1,5 @@
+(fn prepend [head tbl]
+ (doto tbl
+ (table.insert 1 head)))
+
+{ : prepend }
diff --git a/textile.fnl b/textile.fnl
@@ -1,6 +1,7 @@
(import-macros { : define-tests : expect : expect= } :assert)
(local { : to-html } (require :html))
+(local { : prepend } (require :lib))
(fn list-append [a1 a2]
(icollect [_ v (ipairs a2) &into a1] v))
@@ -15,9 +16,7 @@
l))]
(table.concat lines "")))))
-(fn cons-tag [tag content]
- (doto content
- (table.insert 1 tag)))
+
(define-tests :read-blocks
(with-open [f (io.open "tests/paras.txt" :r)]
@@ -224,8 +223,8 @@ filesystem. "])
(fn chop-block [tok block start]
(case (string.find block tok start)
- (s e) (cons-tag (string.sub block start (- s 1))
- (chop-block tok block (+ 1 e)))
+ (s e) (prepend (string.sub block start (- s 1))
+ (chop-block tok block (+ 1 e)))
nil [(string.sub block start)]))
(fn split-list-items [block]
@@ -241,8 +240,8 @@ filesystem. "])
(if tag
(list-append
(or (inline-markup preamble) [])
- [(cons-tag tag (icollect [_ i (ipairs lists)]
- (cons-tag :li (extract-lists i))))])
+ [(prepend tag (icollect [_ i (ipairs lists)]
+ (prepend :li (extract-lists i))))])
(or (inline-markup preamble) []))))
@@ -306,9 +305,7 @@ filesystem. "])
(fn parse-stream [stream]
(icollect [p (read-blocks stream)]
(let [(tag body) (tag-and-body p)]
- (cons-tag tag (extract-lists body)))))
-
-
+ (prepend tag (extract-lists body)))))
(define-tests :parse-stream