tracks/ocaml/exercises/forth/example.ml in trackler-2.2.1.110 vs tracks/ocaml/exercises/forth/example.ml in trackler-2.2.1.111

- old
+ new

@@ -1,27 +1,30 @@ -open Core +open Base let (>|>) f g x = g (f x) +module String_map = Map.M(String) +let emptyStringMap = Map.empty (module String) + let string_to_int (s: string): int option = Option.try_with (fun () -> Int.of_string s) type sentence = | Def of string | Normal of string list type stack = int list type handler = stack -> stack option -type vocabulary = handler String.Map.t +type vocabulary = handler String_map.t let handle_binary_op f = function | x :: y :: xs -> Some ((f y x) :: xs) | _ -> None let std_vocabulary: vocabulary = - String.Map.empty + emptyStringMap |> Map.set ~key:"+" ~data:(handle_binary_op (+)) |> Map.set ~key:"-" ~data:(handle_binary_op (-)) |> Map.set ~key:"*" ~data:(handle_binary_op ( * )) |> Map.set ~key:"/" ~data:(function | x :: y :: xs -> if x = 0 then None else Some ((y/x) :: xs) | _ -> None) |> Map.set ~key:"DUP" ~data:(function | x :: xs -> Some (x :: x :: xs) | _ -> None) @@ -53,10 +56,10 @@ | None -> None | Some stack -> eval_all stack fs ) let to_sentence (words: string): sentence = - if words.[0] = ':' && string_last words = Some ';' + if Char.(words.[0] = ':') && Option.equal Char.equal (string_last words) (Some ';') then Def words else Normal (String.split ~on:' ' words) let rec handle_def vocabulary stack words: (vocabulary * stack) option = let words = String.split ~on:' ' words in \ No newline at end of file