mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-11 23:17:34 +02:00
Adding assoc-get utility.
This commit is contained in:
parent
c14d67a6f7
commit
f252c1bee1
2 changed files with 19 additions and 1 deletions
|
@ -112,6 +112,23 @@
|
|||
(define (alist? x)
|
||||
(and (list? x) (every pair? x)))
|
||||
|
||||
;;> \subsubsubsection{\rawcode{(assoc-get alist key [equal? [default]])}}
|
||||
|
||||
;;> Utility analogous to \scheme{conf-get} on a pure alist. Returns
|
||||
;;> the value of the cell in \var{alist} whose car is \var{equal?} to
|
||||
;;> \var{key}, where the value is determined as the \var{cadr} if the
|
||||
;;> cell is a proper list of two elements and the \var{cdr} otherwise.
|
||||
;;> If no cell is found, returns \var{default}, or \scheme{#f} if
|
||||
;;> unspecified.
|
||||
|
||||
(define (assoc-get alist key . o)
|
||||
(cond
|
||||
((assoc key alist (or (and (pair? o) (car o)) equal?))
|
||||
=> (lambda (x)
|
||||
(if (and (pair? (cdr x)) (null? (cddr x))) (cadr x) (cdr x))))
|
||||
(else
|
||||
(and (pair? o) (pair? (cdr o)) (cadr o)))))
|
||||
|
||||
;;> Returns just the base of \var{config} without any parent.
|
||||
|
||||
(define (conf-head config)
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
(export make-conf conf? conf-load conf-load-in-path conf-load-cascaded
|
||||
conf-verify conf-extend conf-append conf-set conf-unfold-key
|
||||
conf-get conf-get-list conf-get-cdr conf-get-multi
|
||||
conf-specialize read-from-file conf-source conf-head conf-parent)
|
||||
conf-specialize read-from-file conf-source conf-head conf-parent
|
||||
assoc-get)
|
||||
(import (scheme base) (scheme read) (scheme write) (scheme file)
|
||||
(scheme time) (srfi 1))
|
||||
;; This is only used for config verification, it's acceptable to
|
||||
|
|
Loading…
Add table
Reference in a new issue