Is it ok to mutate a hash while iterating over it say in one of ~for~ forms? Specifically I want to filter (that is drop) some keys, but I'm also interested in mutation in general. I guess the answer lies in whether forms like ~in-dict~ etc create lazy streams that hold on to the table?
Relevant docs that I managed to dig out: - hash-map <https://docs.racket-lang.org/reference/hashtables.html?q=hash-map#%28def._%28%28quote._~23~25kernel%29._hash-map%29%29> seems to suggest that at least dropping keys is fine, but that only talks about hash-map procedure specifically not other forms; - caveats concerning concurrent modifications <https://docs.racket-lang.org/reference/hashtables.html?q=hash-map#%28elem._%28caveat._concurrency%29%29> maybe kinda relevant (I've asked <https://groups.google.com/forum/#!searchin/racket-users/mutate$20hash|sort:date/racket-users/vszlDzJYF0Q/5tHh9FmtAgAJ> similar question about concurrency <https://groups.google.com/forum/#!searchin/racket-users/mutate$20hash|sort:date/racket-users/vszlDzJYF0Q/5tHh9FmtAgAJ> some time ago). Here're some examples to be concrete: #+begin_src racket ;; IMO ok according to docs? (hash-map h (λ (k v) (when (pred v) (hash-remove! h k)))) ;; probably ok assuming it translates to hash-map? (dict-map h (λ (k v) (when (pred v) (dict-remove! h k)))) ;; is that ok? (for (((k v) (in-dict h)) #:when (pred v)) (dict-remove! h k)) ;; defensive solution (let ((fails (for/list (((k v) (in-dict h)) #:when (pred v)) k))) (for-each (curry dict-remove! h) fails)) #+end_src That question wouldn't arise were I to deal with immutable data, but I'm not. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/b57fc367-64b3-434b-93bb-ddb0684d26fe%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

