ocaml: phase 6 String.iter/iteri/fold_left/fold_right/to_seq/of_seq (+3 tests, 501 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Six new String functions, all in OCaml syntax inside runtime.sx: iter : index-walk with side-effecting f iteri : iter with index fold_left : thread accumulator left-to-right fold_right: thread accumulator right-to-left to_seq : return a char list (lazy in real OCaml; eager here) of_seq : concat a char list back to a string Round-trip: String.of_seq (List.rev (String.to_seq "hello")) = "olleh" Note: real OCaml's Seq is lazy. We return a plain list because the existing stdlib already provides exhaustive list operations and we don't yet have lazy sequences. If a baseline needs Seq.unfold or similar, we'll graduate to a proper Seq module then.
This commit is contained in:
@@ -1240,6 +1240,14 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 4971)
|
||||
(eval "(ocaml-run \"Format.asprintf \\\"%s=%d\\\" \\\"n\\\" 7\")")
|
||||
|
||||
;; ── String.iter / fold / seq ─────────────────────────────────
|
||||
(epoch 4980)
|
||||
(eval "(ocaml-run \"let n = ref 0 in String.iter (fun c -> n := !n + Char.code c) \\\"abc\\\"; !n\")")
|
||||
(epoch 4981)
|
||||
(eval "(ocaml-run \"String.fold_left (fun acc c -> acc + Char.code c) 0 \\\"hi\\\"\")")
|
||||
(epoch 4982)
|
||||
(eval "(ocaml-run \"String.of_seq (List.rev (String.to_seq \\\"hello\\\"))\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 360 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1968,6 +1976,11 @@ check 4961 "lazy memoization counter=1" '8401'
|
||||
check 4970 "Format.sprintf %d" '"99"'
|
||||
check 4971 "Format.asprintf %s=%d" '"n=7"'
|
||||
|
||||
# ── String.iter / fold_left / seq ───────────────────────────────
|
||||
check 4980 "String.iter sum codes abc" '294'
|
||||
check 4981 "String.fold_left sum hi" '209'
|
||||
check 4982 "String.of_seq (rev to_seq)" '"olleh"'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user