summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemsen2012-09-10 21:56:16 +0200
committerGravatar Tom Willemsen2012-09-10 21:56:16 +0200
commit271b33f91073a4b05a0f2a30bc14b947c7beff69 (patch)
tree218f993c6902b69607fc86fa2bbbec01d9cdf5b9
parent62cde9b1c8a52097b0191fea1554ab7055532aa8 (diff)
downloadundone-271b33f91073a4b05a0f2a30bc14b947c7beff69.tar.gz
undone-271b33f91073a4b05a0f2a30bc14b947c7beff69.zip
Add id to each item
* undone/main.scm (get-field-value): Allow specification of default return if no key is found. (next-id): New function. (add): Add `id' to the todo item.
-rw-r--r--undone/main.scm17
1 files changed, 15 insertions, 2 deletions
diff --git a/undone/main.scm b/undone/main.scm
index 5ac6b2c..2f7c535 100644
--- a/undone/main.scm
+++ b/undone/main.scm
@@ -12,8 +12,13 @@
(define-syntax get-field-value
(lambda (x)
(syntax-case x ()
+ ((_ key alist default)
+ #'(let ((field (get-field key alist)))
+ (if field
+ (cdr field)
+ default)))
((_ key alist)
- #'(cdr (get-field key alist))))))
+ #'(get-field-value key alist #f)))))
(define-syntax define-view
(lambda (x)
@@ -126,6 +131,7 @@
(mkdir path)))
(define (save)
+
"Save the list."
(mkdirs (dirname todo-list-file))
@@ -133,13 +139,20 @@
(write todo-list port)
(close-port port)))
+(define (next-id)
+ "Look through all known todo items and get the next id."
+ (1+ (apply max (map (lambda (elm)
+ (get-field-value id elm 0))
+ todo-list))))
+
(define (add args)
"Add item to the list."
(set! todo-list
(append todo-list
(list
(append
- `((content . ,(string-trim-right (read-delimited ""))))
+ `((id . ,(next-id))
+ (content . ,(string-trim-right (read-delimited ""))))
(map (lambda (arg)
(let* ((pair (string-split arg #\=))
(var (string->symbol (car pair)))