Skip to content
Snippets Groups Projects
Commit 118aad88 authored by Paul IANNETTA's avatar Paul IANNETTA Committed by Thomas Wood
Browse files

Slight additions to mytools.ml

parent 9d6e7022
No related branches found
No related tags found
No related merge requests found
...@@ -47,26 +47,29 @@ let list_mapi f l = ...@@ -47,26 +47,29 @@ let list_mapi f l =
in in
aux 0 l aux 0 l
let range i j =
let rec aux j acc =
if i <= j then aux (j - 1) (j :: acc) else acc in
aux j []
let list_nat n = (* for n >= 0 *) let list_nat n = (* for n >= 0 *)
let rec aux i = range 0 n
if i = 0 then [] else (i-1)::(aux (i-1)) in
List.rev (aux n)
let rec list_separ sep = function let rec list_separ sep = function
| [] -> [] | [] -> []
| a::[] -> a::[] | a :: [] -> a :: []
| a::l -> a::sep::(list_separ sep l) | a :: l -> a :: sep :: list_separ sep l
let rec filter_somes = function let rec filter_somes = function
| [] -> [] | [] -> []
| None::l -> filter_somes l | None :: l -> filter_somes l
| (Some x) :: l -> x :: filter_somes l | (Some x) :: l -> x :: filter_somes l
let list_unique l = let list_unique l =
let rec aux acc = function let rec aux acc = function
| [] -> acc | [] -> acc
| a::q -> | a :: q ->
if List.mem a acc then aux acc q else aux (a::acc) q if List.mem a acc then aux acc q else aux (a :: acc) q
in in
aux [] l aux [] l
...@@ -113,7 +116,7 @@ let list_index k l = ...@@ -113,7 +116,7 @@ let list_index k l =
(**************************************************************) (**************************************************************)
(** String manipulation functions *) (** String manipulation functions *)
let str_cmp (s1:string) (s2:string) = let str_cmp (s1 : string) (s2 : string) =
if s1 < s2 then -1 else if s1 = s2 then 0 else 1 if s1 < s2 then -1 else if s1 = s2 then 0 else 1
let str_starts_with p s = let str_starts_with p s =
...@@ -220,5 +223,12 @@ let warning s = ...@@ -220,5 +223,12 @@ let warning s =
Printf.printf "### WARNING: %s\n" s Printf.printf "### WARNING: %s\n" s
let unsupported s = let unsupported s =
failwith ("Unsupported language construction : " ^ s) failwith ("Unsupported language construction: " ^ s ^ ".")
let out_of_scope s =
failwith (s ^ " are and will not be supported.")
let error s =
failwith ("error: " ^ s ^ ".")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment