summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Nussbaum <lucas@debian.org>2013-07-05 16:16:41 +0200
committerLucas Nussbaum <lucas@debian.org>2013-07-05 16:16:41 +0200
commitc0b508792229069056eb3ac61e8c318f97b3b115 (patch)
tree9352d8d1c8803796f44d37332d2cd5bf84acf671
parentbb72de6a9488be2bd66c4334f82253728ea1e6bc (diff)
parent8085e709222a6dc8c36db9c903119e54874884b4 (diff)
Merge tag 'upstream/0.90+bzr367'
Upstream version 0.90+bzr367
-rw-r--r--EXTRA/pervasivesExtra.ml25
-rw-r--r--EXTRA/pervasivesExtra.mli6
-rw-r--r--Makefile6
-rw-r--r--STRUCTURES/option.ml3
-rw-r--r--STRUCTURES/option.mli1
-rw-r--r--STRUCTURES/thunk.ml13
-rw-r--r--STRUCTURES/thunk.mli6
-rw-r--r--meta.ml.released10
8 files changed, 62 insertions, 8 deletions
diff --git a/EXTRA/pervasivesExtra.ml b/EXTRA/pervasivesExtra.ml
index 4d406da..56b876e 100644
--- a/EXTRA/pervasivesExtra.ml
+++ b/EXTRA/pervasivesExtra.ml
@@ -97,3 +97,28 @@ let for_int ?break ?backward ?(step=1) ~min ~max f acc =
if x < min || (break acc x) then acc else loop (f acc x) (x-step)
in
loop acc min
+
+
+let get_first_line_of_file filename =
+ try
+ let ch = open_in filename in
+ let line = input_line ch in
+ let () = close_in ch in
+ Some line
+ with _ -> None
+
+
+let get_first_lines_of_file filename n =
+ try
+ let ch = open_in filename in
+ let rec loop k acc =
+ if k=0 then List.rev acc else
+ try
+ let line = input_line ch in
+ loop (k-1) (line::acc)
+ with _ -> List.rev acc
+ in
+ let result = loop n [] in
+ let () = close_in ch in
+ result
+ with _ -> []
diff --git a/EXTRA/pervasivesExtra.mli b/EXTRA/pervasivesExtra.mli
index bfdb73d..775b3de 100644
--- a/EXTRA/pervasivesExtra.mli
+++ b/EXTRA/pervasivesExtra.mli
@@ -20,3 +20,9 @@ val round : ?decimals:int -> float -> float
val for_float : ?break:('a -> float -> bool) -> ?backward:unit -> min:float -> max:float -> step:float -> ('a -> float -> 'a) -> 'a -> 'a
val for_int : ?break:('a -> int -> bool) -> ?backward:unit -> ?step:int -> min:int -> max:int -> ('a -> int -> 'a) -> 'a -> 'a
+
+(** The result on empty or non-existent files is None. *)
+val get_first_line_of_file : string -> string option
+
+(** The result on empty or non-existent files is the empty list. *)
+val get_first_lines_of_file : string -> int -> string list
diff --git a/Makefile b/Makefile
index 82923ad..89c6638 100644
--- a/Makefile
+++ b/Makefile
@@ -141,10 +141,10 @@ world: world-local main
# foo.byte : manually_pre_actions
# foo.native : manually_pre_actions
#
-# MANUALLY_PRE_COPY_IN_build = include_as_string.ml USAGE.txt
-# MANUALLY_PRE_MAKE_IN_build = include_as_string.cmo
+# MANUALLY_PRE_COPY_IN_build = include_as_string_p4.ml USAGE.txt
+# MANUALLY_PRE_MAKE_IN_build = include_as_string_p4.cmo
#
-# _build/include_as_string.cmo: include_as_string.ml
+# _build/include_as_string_p4.cmo: include_as_string_p4.ml
# ocamlc -c -I +camlp4 camlp4lib.cma -pp camlp4of -o $@ $<
.PHONY : manually_pre_actions manually_post_actions
diff --git a/STRUCTURES/option.ml b/STRUCTURES/option.ml
index 6c92e5f..dd37087 100644
--- a/STRUCTURES/option.ml
+++ b/STRUCTURES/option.ml
@@ -31,6 +31,9 @@ let map f = function None -> None | Some x -> Some (f x)
let bind x f = match x with None -> None | Some x -> (f x)
let return x = Some x
let iter f = function None -> () | Some x -> (f x)
+let join = function
+| None -> None
+| Some x -> x
(* Monadic definition: *)
let map2 f m1 m2 = bind m1 (function x1 -> map (f x1) m2)
diff --git a/STRUCTURES/option.mli b/STRUCTURES/option.mli
index a5d45fe..c139e25 100644
--- a/STRUCTURES/option.mli
+++ b/STRUCTURES/option.mli
@@ -28,6 +28,7 @@ val bind : 'a option -> ('a -> 'b option) -> 'b option
val return : 'a -> 'a option
val map2 : ('a -> 'b -> 'c) -> 'a option -> 'b option -> 'c option
val bind2 : 'a option -> 'b option -> ('a -> 'b -> 'c option) -> 'c option
+val join : 'a option option -> 'a option
val iter : ('a -> unit) -> 'a option -> unit
val filter : ('a -> bool) -> 'a option -> 'a option
diff --git a/STRUCTURES/thunk.ml b/STRUCTURES/thunk.ml
index d122d28..e2d9fc3 100644
--- a/STRUCTURES/thunk.ml
+++ b/STRUCTURES/thunk.ml
@@ -54,6 +54,19 @@ let of_lazy l = fun () -> Lazy.force l
type id = int
type linear = bool
+let rec first_success pred = function
+| [] -> None
+| t::ts ->
+ let y = t () in
+ (match (pred y) with
+ | false -> first_success pred ts
+ | true -> Some y
+ )
+
+let first_attempt p0 ts =
+ let p1 = function None -> false | Some x -> p0 x in
+ Option.join (first_success p1 ts)
+
module Make_class_with_discipline (M : Container.T_with_identifiers) = struct
let dress_thunk ?fallback ?one_shot thunk =
diff --git a/STRUCTURES/thunk.mli b/STRUCTURES/thunk.mli
index 5b73898..bb04092 100644
--- a/STRUCTURES/thunk.mli
+++ b/STRUCTURES/thunk.mli
@@ -30,6 +30,12 @@ val of_lazy : 'a lazy_t -> 'a t
type id = int
type linear = bool
+(** First thunk providing a suitable result: *)
+val first_success : ('a -> bool) -> 'a t list -> 'a option
+
+(** As first_success, but each thunk may directly fails (None): *)
+val first_attempt : ('a -> bool) -> ('a option) t list -> 'a option
+
(** A queue of 'a thunks. Linear (one-shot) thunks are automatically
removed after each call of apply. Note that the first parameter
of the folder is the accumulator (current state). *)
diff --git a/meta.ml.released b/meta.ml.released
index 8936283..5b09d1a 100644
--- a/meta.ml.released
+++ b/meta.ml.released
@@ -9,8 +9,8 @@ let libraryprefix = "/usr/lib/ocaml";;
let configurationprefix = "/etc";;
let localeprefix = "/usr/local/share/locale";;
let documentationprefix = "/usr/local/share/doc";;
-let uname = "Linux 3.9-1-amd64 #1 SMP Debian 3.9.6-1 x86_64 GNU/Linux";;
-let build_date = "2013-06-22 22:15:43 +0200";;
-let revision = "365";;
-let source_date = "2013-06-04 17:17:28 +0200";;
-let source_date_utc_yy_mm_dd = "2013-06-04";;
+let uname = "Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.41-2 x86_64 GNU/Linux";;
+let build_date = "2013-07-05 15:16:17 +0200";;
+let revision = "367";;
+let source_date = "2013-07-03 17:50:08 +0000";;
+let source_date_utc_yy_mm_dd = "2013-07-03";;