HS: break/continue/until — loop control flow via guard/raise

Parser:
- Add break, continue, exit/halt as parsed commands
- Handle bottom-tested repeat: repeat <body> until <cond>
- Handle bottom-tested repeat: repeat <body> while <cond>

Compiler:
- break → (raise "hs-break"), continue → (raise "hs-continue")
- repeat-until/repeat-while → hs-repeat-until/hs-repeat-while
- for loops use hs-for-each (break/continue aware) instead of for-each

Runtime:
- hs-repeat-times, hs-repeat-forever, hs-repeat-while: wrap body in
  guard to catch hs-break (exit loop) and hs-continue (next iteration)
- Add hs-repeat-until: bottom-tested do-until loop with guard
- Add hs-for-each: break/continue aware iteration over lists

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-20 17:58:58 +00:00
parent 79b3fa3f26
commit f200418d91
3 changed files with 112 additions and 26 deletions

View File

@@ -274,7 +274,7 @@
body)
collection)
(list
(quote for-each)
(quote hs-for-each)
(list (quote fn) (list (make-symbol var-name)) body)
collection)))))
(define
@@ -1105,6 +1105,16 @@
to-val
(if dur (hs-to-sx dur) nil))))
((= head (quote repeat)) (emit-repeat ast))
((= head (quote repeat-until))
(list
(quote hs-repeat-until)
(list (quote fn) (list) (hs-to-sx (nth ast 1)))
(list (quote fn) (list) (hs-to-sx (nth ast 2)))))
((= head (quote repeat-while))
(list
(quote hs-repeat-while)
(list (quote fn) (list) (hs-to-sx (nth ast 1)))
(list (quote fn) (list) (hs-to-sx (nth ast 2)))))
((= head (quote fetch))
(list (quote hs-fetch) (hs-to-sx (nth ast 1)) (nth ast 2)))
((= head (quote fetch-gql))
@@ -1190,6 +1200,10 @@
(nth ast 1)
(nth ast 2)
(if (> (len ast) 3) (nth ast 3) nil)))
((= head (quote break)) (list (quote raise) "hs-break"))
((= head (quote continue))
(list (quote raise) "hs-continue"))
((= head (quote exit)) nil)
((= head (quote on)) (emit-on ast))
((= head (quote init))
(list