summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-05-12 12:32:57 -0700
committerBen Sima <ben@bsima.me>2020-05-12 12:33:37 -0700
commit0bbb74b7b0d8130cfcb71aedd7971e2906362a08 (patch)
tree17c8a542fa3061f81e21d2ad4540d4f0099780f6
parent22b95c42c5b096a3206f80e38b71aac3565ab6b7 (diff)
for -> turn
Inspired by hoon
-rw-r--r--Alpha/Core.scm2
-rw-r--r--Biz/Serval.scm7
-rw-r--r--z.scm24
3 files changed, 12 insertions, 21 deletions
diff --git a/Alpha/Core.scm b/Alpha/Core.scm
index db5975b..0ef1098 100644
--- a/Alpha/Core.scm
+++ b/Alpha/Core.scm
@@ -206,7 +206,7 @@
(define (contains? ls x)
(member? x ls))
-(define (for ls f)
+(define (turn ls f)
(map f ls))
(define (seq x)
diff --git a/Biz/Serval.scm b/Biz/Serval.scm
index 1ccab41..2ea89c2 100644
--- a/Biz/Serval.scm
+++ b/Biz/Serval.scm
@@ -86,11 +86,6 @@
;; should this kit start when the host starts?
(auto-start get-auto-start set-auto-start!))
-(define-syntax for
- (syntax-rules ()
- ((_ a b) (map b a))
- ((_ a ... b) (map b a ...))))
-
(define (zip a b)
"Combine a and b into a single list of pairs."
;; TODO: zip-list, zip-with, in Core
@@ -99,7 +94,7 @@
(define (serialize kit)
"Turns a kit into an association list."
(let* ((fields (record-type-fields @Kit))
- (values (for fields
+ (values (turn fields
(lambda (field) ((record-accessor @Kit field) kit)))))
(zip fields values)))
diff --git a/z.scm b/z.scm
index e379066..46e6fcf 100644
--- a/z.scm
+++ b/z.scm
@@ -155,7 +155,7 @@
(define (index-node id)
(let ([node (load-node id)])
(dict.set *titles* (title node) id)
- (for (tags node)
+ (turn (tags node)
(/. tag
(if tag
(dict.update
@@ -177,14 +177,6 @@
(define (get-by-title title)
(dict.get *titles* title))
- ;; Printing
-
-(define (print-titles)
- (for (list-nodes)
- (lambda (id)
- (pr id) (pr ": ")
- (prn (title (load-node id))))))
-
;; webserver
(define *css* "body{max-width:650px;margin:40px auto;padding:0 10px;font:18px/1.5 -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, \"Noto Sans\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";color:#444}h1,h2,h3{line-height:1.2}@media (prefers-color-scheme: dark){body{color:white;background:#444}a:link{color:#5bf}a:visited{color:#ccf}}")
@@ -240,7 +232,7 @@
['()
(respond
`((ul
- ,@(for (list-nodes)
+ ,@(turn (list-nodes)
(lambda (id)
`(li (a (@ (href ,(fmt "/node/~a" id)))
,(fmt "~a: ~a"
@@ -254,14 +246,14 @@
(let ((tags (dict.keys *tags*)))
(reindex)
(respond
- `((ul ,@(for tags
+ `((ul ,@(turn tags
(lambda [tag]
`(li (a (@ (href ,(fmt "/tag/~a" tag)))
,(fmt "~a" tag)))))))))]
[("tag" tag)
(let ([ids (tagged tag)])
(respond
- `((ul ,@(for ids
+ `((ul ,@(turn ids
(lambda [id]
`(li (a (@ (href ,(fmt "/node/~a" id)))
,(fmt "~a: ~a"
@@ -292,11 +284,15 @@ where 'command' is:
[editor (os.getenv "EDITOR")])
(subprocess.call (list editor (path node)))
(exit EXIT_SUCCESS))]
- [("ls") (print-titles)]
+ [("ls")
+ (turn (list-nodes)
+ (lambda (id)
+ (pr id) (pr ": ")
+ (prn (title (load-node id)))))]
[("tagged" tag)
(begin
(reindex)
- (for (tagged tag)
+ (turn (tagged tag)
(lambda (id)
(pr id)
(pr ": ")