[Libguestfs] [PATCH v11 4/6] builder: add Index.write_entry function
Richard W.M. Jones
rjones at redhat.com
Sun Oct 8 19:38:57 UTC 2017
On Thu, Oct 05, 2017 at 04:58:28PM +0200, Cédric Bosdonnat wrote:
> +open OUnit2
> +open Printf
> +open Unix_utils
> +open Common_utils
We normally separate out the headers according to whether they are
part of the OCaml stdlib, an external library, or our own library.
Therefore I'd write this as:
open Printf
open OUnit2
open Std_utils
open Tools_utils
open Unix_utils
> +let tmpdir = Mkdtemp.temp_dir "guestfs-tests." "";;
> +rmdir_on_exit tmpdir
This is OK, but perhaps more stylish to avoid ‘;;’ by writing:
let tmpdir =
let tmpdir = Mkdtemp.temp_dir "guestfs-tests." "" in
rmdir_on_exit tmpdir;
tmpdir
> +(* Utils. *)
> +let write_entries file entries =
> + let chan = open_out (tmpdir // file) in
> + List.iter (
> + fun (entry) ->
> + Index_parser.write_entry chan entry;
> + ) entries;
You don't need parentheses around ‘(entry)’. In any case these 4
lines can be written much more briefly using currying:
List.iter (Index_parser.write_entry chan) entries;
(https://ocaml.org/learn/tutorials/functional_programming.html#Partial-function-applications-and-currying)
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
More information about the Libguestfs
mailing list