Page
Library
Module
Module type
Parameter
Class
Class type
Source
PdfutilGeneral functions
Typically one will open Pdfutil.
Return the first character of a string, should it have one. Otherwise return None.
Return the first character of a string, should it have one. Otherwise return None.
String representing a list of characters. Fails if list is longer than Sys.max_string_length.
Calling string_replace_all x x' s replaces all instances of x with x' in s, returning a new string.
The same, but provide a function for the replacement string
The standard OCaml starts_with function, for versions of OCaml too old to have it.
Tail-recursive versions of list functions (and some simple variations). See Stdlib for documentation.
Cumulative sum of a list given an initial value. For example, cumulative_sum 1 [2; 3; 4] is [3; 6; 10]
Count the number of elements in a list for which predicate is true.
Map with a function returning an option, dropping all None results and extracting all Some ones.
Like option_map but with a two-argument function and two (equal-length) input lists. Uses List.rev_map2 internally and may raise the same exception.
Similar to rev_map, but 3 arguments.
Similar to map2, but 3 arguments.
Similar to rev_map, but 4 arguments.
Similar to map2, but 4 arguments.
val rev_map5 :
('a -> 'b -> 'c -> 'd -> 'e -> 'f) ->
'a list ->
'b list ->
'c list ->
'd list ->
'e list ->
'f listSimilar to rev_map, but 5 arguments.
val map5 :
('a -> 'b -> 'c -> 'd -> 'e -> 'f) ->
'a list ->
'b list ->
'c list ->
'd list ->
'e list ->
'f listSimilar to map2, but 5 arguments.
val rev_map6 :
('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g) ->
'a list ->
'b list ->
'c list ->
'd list ->
'e list ->
'f list ->
'g listSimilar to rev_map, but 6 arguments.
val map6 :
('a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g) ->
'a list ->
'b list ->
'c list ->
'd list ->
'e list ->
'f list ->
'g listSimilar to map2, but 6 arguments.
take l n takes n elements from the list raising Invalid_argument if there are not enough elements to take or if n < 0.
drop l n drops n elements from the list raising Invalid_argument if n < 0 or there are not enough elements.
Take elements from a list while a given predicate is true, returning them in order.
The same as takewhile, but the list is returned in reverse order.
Drop elements from a list while a given predicate is true.
cleave l n splits l into two parts, returned as a tuple. The first contains the first n elements, the second the remainder. Order is preserved. Invalid_argument is raised on negative argument or not enough elements in list.
Same, but split point controlled by a predicate, which is true for elements in the first returned list. e.g cleavewhile even [2;4;5;6] produces ([2;4], [5;6])
The same as cleavewhile, but the output lists are each unordered.
isolate p p' l isolate a central section of a list l, from the first element after the elements for which predicate p is true, to the element before p' is first true.
Interleave an element among a list, so that interleave 0 [1; 2; 3] yields [1; 0; 2; 0; 3]. An empty or singleton list is unchanged.
Interleave two equal-length lists, taking from the first list first.
Collate a list into a list of lists based upon a comparison function by which it has already been sorted. e.g collate compare [1; 2; 2; 3; 3] calculates [[1]; [2;2]; [3;3]].
Map on lists of lists. So map_lol f is map (map f).
Produce a list of overlapping pairs of elements in a list in order, producing the empty list if on singleton input. e.g pairs [1; 2; 3] is [(1, 2); (2, 3)].
The set setminus a b contains all those elements which are in a but are do not appear in b.
Return a list of the heads of a list of lists, each of which has at least one element, preserving order.
Take a list of lists of equal length, and turn into a list of lists, the first containing all the first elements of the original lists, the second the second, and so on.
Couple the elements of a list l using given function. For instance, couple ( + ) [[1; 3; 5]] is [4; 8]. The two elements are applied to f in the order in which they appear in the input list.
As couple, but an extra unary function is applied to any last (odd) element.
Apply couple repeatedly until only one element remains. Return that element.
A similar function to couple, but the coupling is non-overlapping. So pair ( + ) [1; 2; 3; 4] is 3; 7.
A version of pair which adds a unary function for the singleton, much like couple_ext.
As couple_reduce is to couple, so pair_reduce is to pair.
List.filter has a confusing name, so we define keep and lose to avoid error. keep keeps all those matching the predicate, lose loses all thos matching a predicate.
A version where we need to apply unit each time, for instance when producing a list of random numbers. Result is ordered.
Split a list into some lists of length n (and possibly a final one of length < n), preserving order.
Non-tail recursive version of splitinto, for use only when n is small and fixed.
Split a list at the given positions. Point 1 means after the first element
Select the nth element in a list (first is element 1). Raises Invalid_argument if the number is out-of-range.
replace n x xs replaces the nth element of the list xs with x (the first is element 1)
Produce a list containing all but the last element of a list. For the empty list, returns the empty list.
Find the first and last element of a list. If the list has one element, that is returned twice. If it has no elements, raise Invalid_argument.
Return the first, middle and last elements of a list which has length at least two. Otherwise, raise Invalid_argument.
ilist 2 5 returns [2; 3; 4; 5]. However, ilist 5 2 raises Invalid_argument.
Same as ilist, but return the empty list for ilist x x rather than [x]
Same as ilist_null, but return empty list if start > end, instead of failing
Remove the second, fourth etc. elements from a list, saving the last element (if of even length) e.g drop_evens [1; 2; 3; 4; 5; 6] is [1; 3; 5; 6].
Remove the first, third etc. The last odd element is not saved. e.g drop_odds [1;2;3;4;5;6;7] is [2;4;6].
replaceinlist f x l replaces any element of l for which f l is true with x.
Find the position of the first element matching a predicate. The first element is number one. Fails with Not_found if no element matches the predicate.
Split a list into a list of lists at every point where a predicate is true
lookup x l looks up something, returning None if not found.
Same as lookup, but no option type. Raises Not_found if the key is not there.
add k v l Adds (k, v) to a dictionary, replacing any existing binding of k.
replace k v l replaces the existing binding of k in l with one with binds k to v. Raises Not_found if there is nothing to replace.
Remove something from a list, if it's there. If not, don't complain.
Merge two lists, preferring elements in the second in the case of clashes.
val set : bool ref -> unitSet a boolean reference to true
val clear : bool ref -> unitSet a boolean reference to false
val flip : bool ref -> unitFlip a boolean reference
val (+=) : int ref -> int -> unitval (-=) : int ref -> int -> unitval (/=) : int ref -> int -> unitval (*=) : int ref -> int -> unitOperations on integer references
val (+.=) : float ref -> float -> unitval (-.=) : float ref -> float -> unitval (/.=) : float ref -> float -> unitval (*.=) : float ref -> float -> unitOperations on floating point references
val (=|) : 'a list ref -> 'a -> unitCons something onto the contents of a list reference.
val (=@) : 'a list ref -> 'a list -> unitAppend something to the front of the contents of a list reference.
val mkvector : (float * float) -> (float * float) -> vectormkvector (a, b) (c, d) makes a vector from point (a, b) to point (c, d).
Find the vector pi / 2 anticlockwise from the given one.
val veclength : vector -> floatThe length of a vector.
val mkunitvector : (float * float) -> (float * float) -> vectorMake a unit vector in the direction from one point to a second.
Find the point equidistant between two others.
Cartesian distance between two points.
The largest power of two by which a number is exactly divisible.
The call sign_extend l n extends n of length l bits to fit a native integer
Make sure a floating point number is no degenarate, by making it zero if it is.
val null_hash : unit -> ('a, 'b) Hashtbl.tThe empty zero-sized hash table.
val tryfind : ('a, 'b) Hashtbl.t -> 'a -> 'b optionOption lookup on hashtables
val list_of_hashtbl : ('a, 'b) Hashtbl.t -> ('a * 'b) listMake a list of key-value pairs reflecting the contents of a hash table.
val hashtable_of_dictionary : ('a * 'b) list -> ('a, 'b) Hashtbl.tBuild a hashtable from a dictionary (list of key-value pairs). Items are added from left to right, with no checking for duplicate keys being performed.
val hashset_of_list : 'a list -> ('a, unit) Hashtbl.tBuild a hash set from a list of keys. The values here are ().
Consing to each of a pair of lists at the same time.
Version of conspair where there may or may not be somthing to cons in each case.
Make consecutive elements of an even-length list into a list of pairs.
do_return f g Evaluate f (), evaluate and ignore g (), return f (), in that order.
The smallest box enclosing both given integer boxes. Each box is (xmin, xmax, ymin, ymax).
val box_union_float :
(float * float * float * float) ->
(float * float * float * float) ->
float * float * float * floatThe smallest box enclosing both given floating-point boxes. Each box is (xmin, xmax, ymin, ymax).
val box_overlap :
int ->
int ->
int ->
int ->
int ->
int ->
int ->
int ->
(int * int * int * int) optionThe intersection box (if any) of two integer boxes, each defined as xmin ymin xmax ymax.
val box_overlap_float :
float ->
float ->
float ->
float ->
float ->
float ->
float ->
float ->
(float * float * float * float) optionThe intersection box (if any) of two floating-point boxes, each defined as xmin ymin xmax ymax.
Return a list of leafnames for the given folder in the current folder