# HG changeset patch # User Steve Losh # Date 1675909629 18000 # Node ID 896559ec54b1226b8359f47c45592c989ed986de # Parent bfa9e871b3c0aafe14d70c878f283fed69a4e7d9 Add do-hash-set diff -r bfa9e871b3c0 -r 896559ec54b1 DOCUMENTATION.markdown --- a/DOCUMENTATION.markdown Wed Feb 08 20:42:24 2023 -0500 +++ b/DOCUMENTATION.markdown Wed Feb 08 21:27:09 2023 -0500 @@ -1327,6 +1327,14 @@ +### `DO-HASH-SET` (macro) + + (DO-HASH-SET (SYMBOL HSET) + &BODY + BODY) + +Iterate over `hset` with `symbol` bound to successive elements. + ### `HASH-SET` (struct) Slots: `STORAGE` diff -r bfa9e871b3c0 -r 896559ec54b1 src/hash-sets.lisp --- a/src/hash-sets.lisp Wed Feb 08 20:42:24 2023 -0500 +++ b/src/hash-sets.lisp Wed Feb 08 21:27:09 2023 -0500 @@ -229,3 +229,10 @@ (alexandria:hash-table-keys storage)) +(defmacro do-hash-set ((symbol hset) &body body) + "Iterate over `hset` with `symbol` bound to successive elements." + (with-gensyms (iter found) + `(with-hash-table-iterator (,iter (hash-set-storage ,hset)) + (loop (multiple-value-bind (,found ,symbol) (,iter) + (unless ,found (return nil)) + ,@body))))) diff -r bfa9e871b3c0 -r 896559ec54b1 src/package.lisp --- a/src/package.lisp Wed Feb 08 20:42:24 2023 -0500 +++ b/src/package.lisp Wed Feb 08 21:27:09 2023 -0500 @@ -96,7 +96,9 @@ :hset-filter! :hset-map :hset-map! - :hset-reduce)) + :hset-reduce + + :do-hash-set)) (defpackage :losh.io