Skip to content

Commit 29b1e32

Browse files
authored
Fix instances where the depreciated Core.Caml is used. (#500)
Core.Caml is depreciated in favor of Core.Stdlib. In the cases here I just made it use the Core equivalent functions instead of the ones from the Ocaml stdlib. This fixes a bunch of compiler warns with new core and does not break users who may still have the older version.
1 parent 12e6c23 commit 29b1e32

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

exercises/practice/word-count/.meta/example.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type position =
1111
| Start
1212
| End
1313

14-
let quote_at s ~pos =
14+
let quote_at s ~pos =
1515
let p = match pos with
1616
| Start -> 0
1717
| End -> String.length s - 1
@@ -20,12 +20,12 @@ let quote_at s ~pos =
2020

2121
let word_count s =
2222
let s = String.map s ~f:normalize in
23-
let split =
23+
let split =
2424
List.filter (String.split s ~on:' ') ~f:(Fn.non String.is_empty)
25-
|> List.map ~f:(fun w ->
25+
|> List.map ~f:(fun w ->
2626
let len = String.length w in
27-
if len >= 2 && quote_at w ~pos:Start && quote_at w ~pos:End
28-
then Caml.String.sub w 1 (len - 2)
27+
if len >= 2 && quote_at w ~pos:Start && quote_at w ~pos:End
28+
then String.sub w ~pos:1 ~len:(len - 2)
2929
else w)
3030
in
3131
List.fold ~init:(Map.empty (module String)) ~f:add_to_map split

test-generator/bin_test_gen/test_gen.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let command =
77
let cwd =
88
flag_optional_with_default_doc "w" string Sexp.of_string
99
~aliases:["--cwd"]
10-
~default:(Caml.Sys.getcwd ()) ~doc:"directory to assume as cwd"
10+
~default:(Core_unix.getcwd ()) ~doc:"directory to assume as cwd"
1111
and templates_folder =
1212
flag_optional_with_default_doc "t" string Sexp.of_string
1313
~aliases:["--templates"]

test-generator/lib_generator/exercise.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let of_candidate ~(tpl: string) ~(out: string) (c: Exercise_candidate.t): t =
2020
let to_string (e: t): string =
2121
let print_description = function
2222
| None -> "None"
23-
| Some d -> Caml.Printf.sprintf "%s" d
23+
| Some d -> Printf.sprintf "%s" d
2424
in
2525
Printf.sprintf "ExerciseCandidate { name = \"%s\"; directory = \"%s\"; description = \"%s\"; canonical_data = %s; templates = %s }"
2626
e.name

test-generator/lib_generator/files.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let mkdir_if_not_present dir =
3131

3232
let backup ~(base_folder: string) ~(slug: string) ~(contents: string): bool =
3333
mkdir_if_not_present base_folder;
34-
let path = Caml.Filename.concat base_folder slug in
34+
let path = Filename.concat base_folder slug in
3535
let matches_contents =
3636
Option.try_with (fun () -> In_channel.read_all path)
3737
|> Option.map ~f:(String.equal contents)
@@ -88,7 +88,7 @@ let read_file (p: string): (string, exn) Result.t =
8888
try
8989
let c = Stdio.In_channel.create p in
9090
while true do
91-
Buffer.add_string b (Caml.input_line c);
91+
Buffer.add_string b (In_channel.input_line_exn c);
9292
Buffer.add_char b '\n';
9393
done;
9494
failwith "unreachable"

test-generator/lib_generator/glob.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ let split c s =
44
let len = String.length s in
55
let rec loop acc last_pos pos =
66
if pos = -1 then
7-
Caml.String.sub s 0 last_pos :: acc
7+
String.sub s ~pos:0 ~len:last_pos :: acc
88
else
99
if Char.equal (String.get s pos) c then
1010
let pos1 = pos + 1 in
11-
let sub_str = Caml.String.sub s pos1 (last_pos - pos1) in
11+
let sub_str = String.sub s ~pos:pos1 ~len:(last_pos - pos1) in
1212
loop (sub_str :: acc) pos (pos - 1)
1313
else loop acc last_pos (pos - 1)
1414
in
@@ -21,7 +21,7 @@ let find_substrings ?(start_point=0) substr x =
2121
if len_x - i < len_s
2222
then acc
2323
else
24-
if String.equal (Caml.String.sub x i len_s) substr
24+
if String.equal (String.sub x ~pos:i ~len:len_s) substr
2525
then aux (i::acc) (i + 1)
2626
else aux acc (i + 1)
2727
in

0 commit comments

Comments
 (0)