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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user