haskell: Phase 7 string=[Char] — O(1) string-view head/tail + chr/ord/toUpper/toLower/++ (+35 tests, 810/810)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 49s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-06 19:44:19 +00:00
parent 859361d86a
commit 4a35998469
5 changed files with 315 additions and 69 deletions

View File

@@ -433,10 +433,10 @@
(fn
(a b)
(cond
((hk-str? a) (str (hk-str-to-native a) (hk-str-to-native b)))
((and (list? a) (= (first a) "[]")) b)
((and (list? a) (= (first a) ":"))
(hk-mk-cons (nth a 1) (hk-list-append (nth a 2) b)))
((string? a) (str a b))
(:else (raise "++: not a list")))))
;; Eager finite-range spine — handles [from..to] and [from,next..to].
@@ -839,7 +839,12 @@
(dict-set!
env
"ord"
(hk-mk-builtin "ord" (fn (c) (char-code (hk-force c))) 1))
(hk-mk-builtin
"ord"
(fn
(c)
(let ((v (hk-force c))) (if (number? v) v (char-code v))))
1))
(dict-set!
env
"isAlpha"
@@ -848,11 +853,13 @@
(fn
(c)
(let
((code (char-code (hk-force c))))
(hk-of-bool
(or
(and (>= code 65) (<= code 90))
(and (>= code 97) (<= code 122))))))
((v (hk-force c)))
(let
((code (if (number? v) v (char-code v))))
(hk-of-bool
(or
(and (>= code 65) (<= code 90))
(and (>= code 97) (<= code 122)))))))
1))
(dict-set!
env
@@ -862,12 +869,14 @@
(fn
(c)
(let
((code (char-code (hk-force c))))
(hk-of-bool
(or
(and (>= code 65) (<= code 90))
(and (>= code 97) (<= code 122))
(and (>= code 48) (<= code 57))))))
((v (hk-force c)))
(let
((code (if (number? v) v (char-code v))))
(hk-of-bool
(or
(and (>= code 65) (<= code 90))
(and (>= code 97) (<= code 122))
(and (>= code 48) (<= code 57)))))))
1))
(dict-set!
env
@@ -877,8 +886,10 @@
(fn
(c)
(let
((code (char-code (hk-force c))))
(hk-of-bool (and (>= code 48) (<= code 57)))))
((v (hk-force c)))
(let
((code (if (number? v) v (char-code v))))
(hk-of-bool (and (>= code 48) (<= code 57))))))
1))
(dict-set!
env
@@ -888,9 +899,11 @@
(fn
(c)
(let
((code (char-code (hk-force c))))
(hk-of-bool
(or (= code 32) (= code 9) (= code 10) (= code 13)))))
((v (hk-force c)))
(let
((code (if (number? v) v (char-code v))))
(hk-of-bool
(or (= code 32) (= code 9) (= code 10) (= code 13))))))
1))
(dict-set!
env
@@ -900,8 +913,10 @@
(fn
(c)
(let
((code (char-code (hk-force c))))
(hk-of-bool (and (>= code 65) (<= code 90)))))
((v (hk-force c)))
(let
((code (if (number? v) v (char-code v))))
(hk-of-bool (and (>= code 65) (<= code 90))))))
1))
(dict-set!
env
@@ -911,15 +926,47 @@
(fn
(c)
(let
((code (char-code (hk-force c))))
(hk-of-bool (and (>= code 97) (<= code 122)))))
((v (hk-force c)))
(let
((code (if (number? v) v (char-code v))))
(hk-of-bool (and (>= code 97) (<= code 122))))))
1))
(dict-set!
env
"chr"
(hk-mk-builtin "chr" (fn (n) (char-from-code (hk-force n))) 1))
(dict-set!
env
"toUpper"
(hk-mk-builtin
"toUpper"
(fn
(n)
(let
((code (hk-force n)))
(if (and (>= code 97) (<= code 122)) (- code 32) code)))
1))
(dict-set!
env
"toLower"
(hk-mk-builtin
"toLower"
(fn
(n)
(let
((code (hk-force n)))
(if (and (>= code 65) (<= code 90)) (+ code 32) code)))
1))
(dict-set!
env
"digitToInt"
(hk-mk-builtin
"digitToInt"
(fn (c) (- (char-code (hk-force c)) 48))
(fn
(c)
(let
((v (hk-force c)))
(- (if (number? v) v (char-code v)) 48)))
1))
(dict-set!
env