Sujet : Re: Newbie Question: How do I mass-populate a hash table?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.schemeDate : 25. Sep 2024, 04:26:55
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vcvvtu$3i202$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Populating a hash table using a property list. A property list
has a form like '(one "ONE" two "TWO" ....).
(defun populate-hash-table (table property-list)
(loop for (key value) on property-list by #'cddr
do (setf (gethash key table) value)))
Gauche Scheme
(define (prop-list->alist plist)
(do ((al '()))
((null? plist) al)
(push! al (cons (pop! plist) (pop! plist)))))
(prop-list->alist '(foo 33 bar 42 k 99))
===>
((k . 99) (bar . 42) (foo . 33))