From fd721e94532ba7f912d13706b3c03056345952e6 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 9 May 2020 22:18:17 -0700 Subject: Index titles Also don't overwrite srfi-1 stuff, and added an re module. --- Alpha/Core.scm | 22 ++-------------------- re.scm | 7 +++++++ z.scm | 36 +++++++++++++++++++++++++++++------- 3 files changed, 38 insertions(+), 27 deletions(-) create mode 100644 re.scm diff --git a/Alpha/Core.scm b/Alpha/Core.scm index 997bc4f..192a74f 100644 --- a/Alpha/Core.scm +++ b/Alpha/Core.scm @@ -2,9 +2,8 @@ #:use-module ((ice-9 format)) #:use-module ((system vm program)) #:use-module ((ice-9 rdelim) #:select (read-line)) - #:use-module ((srfi srfi-1) #:select (any)) - #:export (fmt printf pr prn - first ffirst second rest last butlast + #:use-module (srfi srfi-1) + #:export (fmt printf pr prn rest last butlast true? false? some? empty? -> ->> fn /. curry comp repeat @@ -29,13 +28,6 @@ acc (foldl f (f acc (car lst)) (cdr lst)))) -(define fold foldl) - -(define (unfold f init pred) - (if (pred init) - (cons init '()) - (cons init (unfold f (f init) pred)))) - (define (sum lst) (fold + 0 lst)) (define (product lst) (fold * 1 lst)) @@ -62,19 +54,9 @@ (define (empty? a) (equal? a '())) -(define (first a) - "Return the first item in the collection." - (if (pair? a) - (car a) - '())) - (define (ffirst a) (first (first a))) -(define (second a) - "Returns the next item after the first." - (cadr a)) - (define (rest a) "Returns a list of the items after the first." (cdr a)) diff --git a/re.scm b/re.scm new file mode 100644 index 0000000..b4f3dca --- /dev/null +++ b/re.scm @@ -0,0 +1,7 @@ +#!r6rs +(library (re (0)) + (export match) + (import (rnrs base (6)) + (ice-9 regex)) + (define (match s pat) + (string-match pat s))) diff --git a/z.scm b/z.scm index 0267a7d..6e8972a 100644 --- a/z.scm +++ b/z.scm @@ -1,5 +1,8 @@ (import (Alpha Core)) -(import (prefix (Alpha String) string/)) +(import (prefix (Alpha String) string.)) +(import (srfi srfi-1)) +(import (only (srfi srfi-19) date->string current-date)) +(import (prefix (re) re.)) ;; general functions @@ -9,7 +12,7 @@ (define (os.path.expanduser path) (let ([home (getenv "HOME")]) - (string/replace path "~" home))) + (string.replace path "~" home))) (import (only (srfi srfi-1) remove)) (define (rm ls item) @@ -49,8 +52,8 @@ (define (path->id fname) "Given a path, parse out the node id." (-> fname - (string/replace ".md" "") - (string/replace *zdir* "") + (string.replace ".md" "") + (string.replace *zdir* "") (string->id))) (define (id->path id) @@ -86,12 +89,31 @@ (format file "tags:\n") (display "---\n" file)))) +(define (read-node id) + (readlines (id->path id))) + (define (cat-node id) - (prn (readlines (id->path id)))) + (prn (read-node id))) ;; Indexing +(define (get-title id) + (-> id + read-node + (re.match "title: ([^\n]*)") + (match:substring 1))) + +(define (index-titles) + (fold + (lambda (node ls) (acons (get-title node) node ls)) + '() + (list-nodes))) + +(define (get-by-title title) + (let ([index (index-titles)]) + (assoc title index))) + (comment - (define index-titles) + (define index-tags) (define index-links) - (define index-tags)) + ) -- cgit v1.2.3