On Tue, Feb 04, 2025 at 08:08:13AM +0000, Richard W.M. Jones wrote: > On Mon, Feb 03, 2025 at 02:35:20PM -0500, Cole Robinson wrote: > > + ignore (g#sh cmd); > > To be clear what's happening with this line of code: > > 'ignore' is an internal OCaml function that throws away the normal > result of the command.
More on this ... 'ignore' has type: val ignore : 'a -> unit where 'a is read as "alpha", and means "any type", and unit is a bit like void in C. So it's a function that takes a single parameter of any type and returns nothing, and as a side effect ignores the parameter. The OCaml compiler warns if the result of a statement is not used, since that can indicate a bug. For example: $ rlwrap ocaml # let f () = 2+5; () ;; Warning 10 [non-unit-statement]: this expression should have type unit. val f : unit -> unit = <fun> (The warning applies to the statement '2+5' which is calculated but then not used). In virt-v2v we convert these warnings into hard errors using the OCaml compiler equivalent of -Werror. When you really want to calculate something and ignore the result, you have to use ignore (...) around it, eg: # let f () = ignore (2+5); () ;; val f : unit -> unit = <fun> 'ignore' is needed above because g#sh returns stdout of the command (in the non-error case), which we're not interested in. 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 _______________________________________________ Libguestfs mailing list -- guestfs@lists.libguestfs.org To unsubscribe send an email to guestfs-le...@lists.libguestfs.org