ocaml: phase 5.1 caesar.ml baseline (ROT13 + s.[i] + Char ops)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Side-quests required to land caesar.ml:
1. Top-level 'let r = expr in body' is now an expression decl, not a
broken decl-let. ocaml-parse-program's dispatch now checks
has-matching-in? at every top-level let; if matched, slices via
skip-let-rhs-boundary (which already opens depth on a leading let
with matching in) and ocaml-parse on the slice, wrapping as :expr.
2. runtime.sx: added String.make / String.init / String.map. Used by
caesar.ml's encode = String.init n (fun i -> shift_char s.[i] k).
3. baseline run.sh per-program timeout 240->480s (system load on the
shared host frequently exceeds 240s for large baselines).
caesar.ml exercises:
* the new top-level let-in expression dispatch
* s.[i] string indexing
* Char.code / Char.chr round-trip math
* String.init with a closure that captures k
Test value: Char.code r.[0] + Char.code r.[4] after ROT13(ROT13('hello')) = 104 + 111 = 215.
This commit is contained in:
@@ -360,6 +360,20 @@
|
||||
let split_on_char c s = _string_split_on_char c s
|
||||
let replace_all s a b = _string_replace s a b
|
||||
let index_of s sub = _string_index_of s sub
|
||||
let make n c =
|
||||
let rec aux i acc = if i = 0 then acc else aux (i - 1) (acc ^ c) in
|
||||
aux n \"\"
|
||||
let init n f =
|
||||
let rec aux i acc =
|
||||
if i >= n then acc else aux (i + 1) (acc ^ f i)
|
||||
in
|
||||
aux 0 \"\"
|
||||
let map f s =
|
||||
let rec aux i acc =
|
||||
if i >= _string_length s then acc
|
||||
else aux (i + 1) (acc ^ f (_string_get s i))
|
||||
in
|
||||
aux 0 \"\"
|
||||
end ;;
|
||||
|
||||
module Bytes = struct
|
||||
|
||||
Reference in New Issue
Block a user