HS: fix hs-for-each to handle dicts and nil collections

hs-for-each now converts dicts to key lists and nil to empty list
before iterating, fixing regression where for-in loops over object
properties stopped working after the for-each → hs-for-each switch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-20 18:05:59 +00:00
parent f200418d91
commit c25ab23709

View File

@@ -377,19 +377,21 @@
hs-for-each hs-for-each
(fn (fn
(fn-body collection) (fn-body collection)
(define (let
do-loop ((items (cond ((list? collection) collection) ((dict? collection) (keys collection)) ((nil? collection) (list)) (true (list)))))
(fn (define
(items) do-loop
(when (fn
(not (empty? items)) (remaining)
(let (when
((signal (guard (e (true (str e))) (do (fn-body (first items)) nil)))) (not (empty? remaining))
(cond (let
((= signal "hs-break") nil) ((signal (guard (e (true (str e))) (do (fn-body (first remaining)) nil))))
((= signal "hs-continue") (do-loop (rest items))) (cond
(true (do-loop (rest items)))))))) ((= signal "hs-break") nil)
(when (list? collection) (do-loop collection)))) ((= signal "hs-continue") (do-loop (rest remaining)))
(true (do-loop (rest remaining))))))))
(do-loop items))))
(define (define
hs-fetch hs-fetch