From c25ab2370903f448b871c0300555eea0d397812b Mon Sep 17 00:00:00 2001 From: giles Date: Mon, 20 Apr 2026 18:05:59 +0000 Subject: [PATCH] HS: fix hs-for-each to handle dicts and nil collections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- lib/hyperscript/runtime.sx | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/hyperscript/runtime.sx b/lib/hyperscript/runtime.sx index 6f8ac0ae..3395b461 100644 --- a/lib/hyperscript/runtime.sx +++ b/lib/hyperscript/runtime.sx @@ -377,19 +377,21 @@ hs-for-each (fn (fn-body collection) - (define - do-loop - (fn - (items) - (when - (not (empty? items)) - (let - ((signal (guard (e (true (str e))) (do (fn-body (first items)) nil)))) - (cond - ((= signal "hs-break") nil) - ((= signal "hs-continue") (do-loop (rest items))) - (true (do-loop (rest items)))))))) - (when (list? collection) (do-loop collection)))) + (let + ((items (cond ((list? collection) collection) ((dict? collection) (keys collection)) ((nil? collection) (list)) (true (list))))) + (define + do-loop + (fn + (remaining) + (when + (not (empty? remaining)) + (let + ((signal (guard (e (true (str e))) (do (fn-body (first remaining)) nil)))) + (cond + ((= signal "hs-break") nil) + ((= signal "hs-continue") (do-loop (rest remaining))) + (true (do-loop (rest remaining)))))))) + (do-loop items)))) (define hs-fetch