Frama-C API - List
Extension of OCaml's Stdlib.List module. @see https://frama-c.com/download/frama-c-plugin-development-guide.pdf
Monad
include module type of Stdlib.List
Datatype functions
val hash : ('a -> int) -> 'a t -> intCompute a hash for the list given a hash for the elements.
val pretty : ?format:(Pretty.tformatter -> unit) Pretty.format -> ?item:('a Pretty.aformatter -> 'a -> unit) Pretty.format -> ?sep:unit Pretty.format -> ?last:unit Pretty.format -> ?empty:unit Pretty.format -> (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> 'a t -> unitPretty prints a list given a printer for the elements.
val pretty_text : ?format:(Pretty.tformatter -> unit) Pretty.format -> ?item:('a Pretty.aformatter -> 'a -> unit) Pretty.format -> ?sep:unit Pretty.format -> ?last:unit Pretty.format -> ?empty:unit Pretty.format -> (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> 'a t -> unitPretty prints the list as a user readable text.
Iterators
Returns the index (starting at 0) of the first element verifying the condition. Appears in Ocaml 5.1.
Same as Stdlib.List.map2 but gives the index of the current element to f
Same as Stdlib.List.map but avoid creating a copy of the list's tail if the mapped function returns its argument (tested through physical equality).
Same as Stdlib.List.concat_map but avoid creating a copy of the list's tail if the mapped function returns a singleton list with its argument (tested through physical equality).
Accessors
take n l returns the first n elements of the list. Tail recursive. It returns an empty list if n is nonpositive and the whole list if n is greater than List.length l. This function is introduced in OCaml 5.3 and is made available here until OCaml 5.4 is the minimal supported version. (The 5.3 version is raising exceptions on negative n values) It is equivalent to slice ~last:n l.
drop n l returns the list without the first n elements. It returns the whole list if n is nonpositive and an empty list if n is greater than List.length l. This function is introduced in OCaml 5.3 and is made available here until OCaml 5.4 is the minimal supported version. (The 5.3 version is raising exceptions on negative n values) It is equivalent to slice ~first:n l.
break n l returns a couple of the list of the first n elements and the list of the remaining elements. If n is smaller than 0 (resp. greater than the list length) then ([], l) is returned (resp. (l, [])). It is equivalent to (take n l, drop n l).
slice ?first ?last l is equivalent to Python's slice operator (lfirst:last): returns the range of the list between first (inclusive) and last (exclusive), starting from 0. If omitted, first defaults to 0 and last to List.length l. Negative indices are allowed, and count from the end of the list. slice never raises exceptions: out-of-bounds arguments are clipped, and inverted ranges result in empty lists.
Mutators
replace cmp x l replaces the first element y of l such that cmp x y is true by x. If no such element exists, x is added at the tail of l.
Product of lists
product_map f l1 l2 applies f to all the pairs of an elt of l1 and an element of l2.
product_fold f acc l1 l2 is similar to fold_left f acc l12 with l12 the list of all pairs of an elt of l1 and an elt of l2
Conversion
Combinations
combinations k l computes the combinations of k elements from list l. E.g. combinations 2 [1;2;3;4] = [[1;2];[1;3];[1;4];[2;3];[2;4];[3;4]]. This function preserves the order of the elements in l when computing the sublists. l should not contain duplicates.
