Dictionary reduce, prepare members-base usage.

This commit is contained in:
Dominik Pantůček 2023-03-16 11:24:04 +01:00
parent e26b78b254
commit 77204b80e4
3 changed files with 56 additions and 5 deletions

View file

@ -117,6 +117,15 @@
#t
(loop (cdr lst))))))
;; Returns the first 4-digit symbol from the list.
(define (get-4digit-symbol-from-list lst)
(let loop ((lst lst))
(if (null? lst)
#f
(if (is-4digit-symbol? (car lst))
(car lst)
(loop (cdr lst))))))
;; Returns dictionary containing only records with either 4-digit
;; name or one of its aliases being 4-digit.
(define (files-dictionary-filter-4digit-symbols d)
@ -138,7 +147,8 @@
(make-pathname mdir fname)))))
;; Loads members database, if the second argument is true, shows
;; progress.
;; progress. Members database is a dictionary with id being the key
;; (number) and member record being the value.
(define (load-members dn . opts)
(let ((progress? (and (not (null? opts))
(car opts))))
@ -147,17 +157,33 @@
(let* ((fss (files-dictionary-filter-4digit-symbols
(files+symlinks->files-dictionary
(get-files+symlinks dn))))
(mb (dict-map
(mb0 (dict-map
(lambda (symfn symlinks)
(when progress?
(display "."))
(members-base-load-member dn
(symbol->string symfn)
symlinks))
fss)))
fss))
(mb (dict-reduce (make-dict)
(lambda (acc key val)
#f)
mb0)))
(when progress?
(print " ok."))
mb)))
mb0)))
(define (find-member-by-id mb id)
#f)
(define (find-member-by-nick mb nick)
#f)
(define (list-members-ids mb)
#f)
(define (list-members-nicks mb)
#f)
;; Performs self-tests of this module.
(define (members-base-tests!)
@ -181,6 +207,9 @@
(test-false is-4digit-symbol? (is-4digit-symbol? '|ABC|))
(test-true list-contains-4digit-symbol? (list-contains-4digit-symbol? '(|0000| abc |666|)))
(test-false list-contains-4digit-symbol? (list-contains-4digit-symbol? '(|00000| abc |666|)))
(test-eq? get-4digit-symbol-from-list
(get-4digit-symbol-from-list '(|000| abc |6666| qwer))
'|6666|)
))
)