Implement and document new ldict-map.
This commit is contained in:
parent
5533a3256e
commit
bd7421b626
2 changed files with 29 additions and 8 deletions
|
@ -41,10 +41,13 @@
|
|||
ldict-set
|
||||
|
||||
ldict-keys
|
||||
|
||||
ldict-map
|
||||
ldict-filter
|
||||
ldict-reduce
|
||||
|
||||
ldict-update
|
||||
|
||||
ldict-tests!
|
||||
)
|
||||
|
||||
|
@ -151,18 +154,20 @@
|
|||
;; Maps dictionary values, the procedure gets key-value pairs if it
|
||||
;; accepts more than one argument. If it accepts a third argument,
|
||||
;; index gets passed as well.
|
||||
(define (dict-map proc d)
|
||||
(define (ldict-map proc ld)
|
||||
(let* ((lpi (length (procedure-information proc)))
|
||||
(both? (> lpi 2))
|
||||
(index? (> lpi 3)))
|
||||
(let loop ((d d)
|
||||
(r '())
|
||||
(let loop ((pairs (ldict-pairs))
|
||||
(res '())
|
||||
(i 0))
|
||||
(if (null? d)
|
||||
r ; No reverse needed, order does not matter
|
||||
(loop (cdr d)
|
||||
(let ((k (caar d))
|
||||
(v (cdar d)))
|
||||
(if (null? pairs)
|
||||
(cons TAG-LDICT
|
||||
(cons (ldict-meta ld)
|
||||
res))
|
||||
(loop (cdr pairs)
|
||||
(let ((k (caar pairs))
|
||||
(v (cdar pairs)))
|
||||
(cons (cons k (if both?
|
||||
(if index?
|
||||
(proc k v i)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue