(define (flatten-alist alist)
;; The AList is of the form (("name" . category) ...)
;; Looks for all sub-categories of CATEGORY, and handles the PICS
;; convention of using "parent"/"child" for the name of nested
;; categories. Returns an AList of the same form, with the nested
;; categories added to the top level.
(map (lambda (name-and-category)
(let ((name (car name-and-category))
(category (cdr name-and-category)))
(let ((sub-categories
(->category-alist (cdr category))))
;; SUB-CATEGORIES is an AList of the correct form, but
;; the names are wrong because they don't have the parent
;; name in them yet.
(map (lambda (old-name category)
(cons (string-append name "/" old-name)
category))
(map car sub-categories)
(map cdr sub-categories)))))
alist))