Sujet : map-plist
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.schemeDate : 02. Jul 2025, 04:35:06
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <10429d7$3acad$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Pascal Bourguignon wrote:
(defun map-plist (fun plist)
(loop :for (key value) on plist by #'cddr
:collect (funcall fun key value))
...
Then you can write:
(map-plist (lambda (k v) (cons k (1+ v))) '(one 1 two 2 three 3))
Gauche Scheme
(use util.match) ;; match-lambda
(use gauche.lazy) ;; lslices
(map
(match-lambda [(k v) (cons k (+ 1 v))])
(lslices '(one 1 two 2 three 3) 2))
===>
((one . 2) (two . 3) (three . 4))