diff --git a/undone/main.scm b/undone/main.scm index e34450c..cac9581 100644 --- a/undone/main.scm +++ b/undone/main.scm @@ -1,6 +1,7 @@ (define-module (undone main) #:use-module (ice-9 format) #:use-module (ice-9 rdelim) + #:use-module (oop goops) #:export (main)) (define-syntax get-field @@ -165,6 +166,41 @@ (string->number (car args))))) todo-list))) +(define-class ()) + +(define-generic print-view) +(define-generic sort-view) +(define-generic filter-view) + +(define-method (sort-view (v ) l) + l) + +(define-method (filter-view (v )) + (lambda (elm) + (and (assq 'id elm) (assq 'content elm)))) + +(define-method (print-view (v )) + (for-each + (lambda (item) + (let ((id (let ((field (assq 'id item))) + (and field (cdr field)))) + (content + (let ((field (assq 'content item))) + (and field (cdr field))))) + (if #t (format #t "~2d ~a~%" id content)))) + (filter (filter-view v) + (sort-view v todo-list)))) + +(define-class ()) + +(define-method (sort-view (v ) l) + (reverse l)) + +(define-method (filter-view (v )) + (lambda (elm) + (let ((id (assq 'id elm))) + (and id (> (cdr id) 4))))) + (define-view default "Default todo-list view, show only the title." "~2d ~a~%" id content) @@ -208,4 +244,6 @@ (lambda (view) (format #t "~a~20t~a~%" (car view) (procedure-documentation (cdr view)))) - view-list))))) + view-list)))) + + (print-view (make )))