[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] Re: factorization would be nice



On Wed, Aug 12, 2009 at 09:15:31AM +0100, Richard W.M. Jones wrote:
> On Wed, Aug 12, 2009 at 10:07:16AM +0200, Jim Meyering wrote:
> >            List.iter (
> >              function
> >              | Pathname n ->
> >                  pr "  char *%s = args.%s;\n" n n;
> >                  pr "  ABS_PATH (%s, goto done);\n" n;
> >              | Device n ->
> >                  pr "  char *%s = args.%s;\n" n n;
> >                  pr "  RESOLVE_DEVICE (%s, goto done);" n;
> > 	     | Dev_or_Path n ->

On thing to add here:

The 'n's in this code are all different bindings.  So there's no way
to get a closure which captures the values of all 'n's.

Thus in other code (but not in this case) you could have written:

  let pr_args () =
    pr "  char *%s = args.%s\n" n n
  in

where the value of 'n' would be captured in the closure 'pr_args', and
not have to be given explicitly each time.

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://et.redhat.com/~rjones/libguestfs/
See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]