From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q2DAnmKq016814 for ; Tue, 13 Mar 2012 11:49:48 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AokBAL8lX0/RVdc2kGdsb2JhbABDrGQBiHMIIgEBAQEJCQ0HFAQjgiICExkBGx4DEgkBBl0BEQEFAT0ah2icWYJdCot4gnGFLj+IdAEFC404gyIElU+ORT2EBw X-IronPort-AV: E=Sophos;i="4.73,575,1325458800"; d="scan'208";a="149049821" Received: from mail-lpp01m010-f54.google.com ([209.85.215.54]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 13 Mar 2012 11:49:43 +0100 Received: by lagv3 with SMTP id v3so633826lag.27 for ; Tue, 13 Mar 2012 03:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=awPEzwdjNDqfTfdYVFQhIb7/lLOib7d2RprAvRVlnWE=; b=0crnRVnmI+7ULgYc2Qg4MyXJXTUnhnHb1mkL4w92kC9yOYEEZyzb6vnWzc8ievNA/6 jGaS/rFP4wi58X4N6BHRbLnDIeHerdJgBJ93GEULLqbg7eQXbifaB6RTIg8B/9hVxXKX IoSNok3kMoOB1DCXWhKPM2o7VRYWca4ZVh68cnUzr+wmZdpy/z0PyEwB0xFlYNpAVsox m7Pr0JYWoLEWmmwiaow3hj+nmpVbLaS7bOpIv7VIr0AgV6gZi/nOJNeN4YJgZyLkPegC MFEF11Yo302hS0m/ZWcaaU1X/mBjcaAxMUCOsfNhg36iyO0HCUp9ApzxUE2xxF8n1x3J +1TQ== Received: by 10.152.128.38 with SMTP id nl6mr11821340lab.15.1331635782239; Tue, 13 Mar 2012 03:49:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.152.25.73 with HTTP; Tue, 13 Mar 2012 03:49:10 -0700 (PDT) From: Gabriel Cardoso Date: Tue, 13 Mar 2012 11:49:10 +0100 Message-ID: To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=f46d043086c0c5444304bb1d9de2 Subject: [Caml-list] Problem with Arg.Tuple --f46d043086c0c5444304bb1d9de2 Content-Type: text/plain; charset=ISO-8859-1 Dear list, I have empty arguments when using Arg.Tuple with references. This minimalist example illustrates my problem : let f a b = print_endline a; print_endline b let s = ref "" let speclist = [( "-a", Arg.Tuple [ Arg.Set_string s; Arg.String (f !s) (* !s is empty !!! *) (* Arg.String (fun ss -> f !s ss) (\* Works just fine ... why ? *\) *) ], "doc" )] let _ = Arg.parse speclist (fun s -> ()) "usage" -------------------- $ ocamlc test.ml $ /a.out -a x y y ------------------------ When uncommenting the line 12 : ------------------------ $ ocamlc test.ml $ ./a.out -a x y x y ------------------------- Any idea what am I doing wrong ? Thanks in advance ! Gabriel --f46d043086c0c5444304bb1d9de2 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Dear list,=A0

I have empty arguments whe= n using Arg.Tuple with references. This minimalist example illustrates my p= roblem :

let f a b =3D
=A0 print_endline= a;
=A0 print_endline b

let s =3D ref ""= ;

let speclist =3D [(
=A0 "-a"= ,
=A0 Arg.Tuple [
=A0 =A0 Arg.Set_string s;
= =A0 =A0 Arg.String (f !s) (* !s is empty !!! *)
=A0 =A0 (* Arg.String (fun ss -> f !s ss) (\* Works just fine ... w= hy ? *\) *)
=A0 ],
=A0 "doc"
)]

let _ =3D Arg.parse speclist (fun s -> ()) "u= sage"

--------------------
$ ocamlc test.ml
$ /a.out -a x y

y
------------------------

When uncommenti= ng the line 12 :=A0
------------------------
$ ocamlc test.ml
$ ./a.out -a x y
x
y
----= ---------------------

Any idea what am I doing wro= ng ?

Thanks in advance !

Gabriel
--f46d043086c0c5444304bb1d9de2-- From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q2DBR71R018692 for ; Tue, 13 Mar 2012 12:27:07 +0100 Resent-Message-Id: <201203131127.q2DBR71R018692@walapai.inria.fr> X-IronPort-AV: E=Sophos;i="4.73,575,1325458800"; d="scan'208";a="135793113" Received: from rhodamine.loria.fr ([152.81.2.177]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/AES128-SHA; 13 Mar 2012 12:27:01 +0100 Mime-Version: 1.0 (Apple Message framework v1257) Content-Type: text/plain; charset=windows-1252 From: Samuel Hornus Resent-From: Samuel Hornus In-Reply-To: Date: Tue, 13 Mar 2012 12:21:12 +0100 Resent-Date: Tue, 13 Mar 2012 12:27:01 +0100 Message-Id: References: Resent-To: O Caml To: Gabriel Cardoso X-Mailer: Apple Mail (2.1257) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id q2DBR71R018692 Subject: Re: [Caml-list] Problem with Arg.Tuple On Mar13, 2012, at 11:49 , Gabriel Cardoso wrote: > Dear list, > > I have empty arguments when using Arg.Tuple with references. This minimalist example illustrates my problem : > > let f a b = > print_endline a; > print_endline b > > let s = ref "" > > let speclist = [( > "-a", > Arg.Tuple [ > Arg.Set_string s; > Arg.String (f !s) (* !s is empty !!! *) Here, the value of !s is empty when the (f !s) is evaluated… you shoud pass the whole reference as argument : Arg.String(f s) and let f a b = print_endline !a; print_endline b > (* Arg.String (fun ss -> f !s ss) (\* Works just fine ... why ? *\) *) why ? because the !s is evaluated only later, when the anonymous function (fun ss ->…) is applied. -- Sam From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q2DCOPJj021686 for ; Tue, 13 Mar 2012 13:24:25 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: At4BAPk7X0/RVdm2mWdsb2JhbABDtVgIIgEBAQEBCAsLBxQnggkBAQEDARICExkBGx0BAwELBgUEAQYNLiIBEQEFARwGEyKHYwWfLQqLeIJxhS0/iHQBBQuQWgSVT45FPYQH X-IronPort-AV: E=Sophos;i="4.73,575,1325458800"; d="scan'208";a="149074466" Received: from mail-lb0-f182.google.com ([209.85.217.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 13 Mar 2012 13:24:24 +0100 Received: by lboi15 with SMTP id i15so395964lbo.27 for ; Tue, 13 Mar 2012 05:24:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=K2JPLnZgXO3z4ijZpSg/2CVU+Gav274R9eSVfDtHBO0=; b=vcQbKRsFAeWniVqzVzlK8FLb1JyVisjgJH72XEkFXD4k4sI7Wzjs2iZjonLnFkGEal jhGj5UQABL4A72qklcna7edPBfIOer/TmYF6ceBZfueoghcEUbLxDqECVyWsqV9QZ8fN DM94c+zDMml72env8qsNb3w3RYdtlAGA+7b9pBb1ZYTjRKl76cTY7yH6EjybegYE0aDb l3RyItjqD9O4INtDzM2UTmGHydIUhLP+oX/buRCogo8h2mPLsI9yLEEaH7/UON5V8kbT vDPZAfgCj92oKhEeZDW9+haNVmZI4puFjfX1CNSeH4NdWrPkrF1JnsjoCmEdbL9UJr41 lJTw== Received: by 10.152.128.38 with SMTP id nl6mr12037106lab.15.1331641463912; Tue, 13 Mar 2012 05:24:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.152.25.73 with HTTP; Tue, 13 Mar 2012 05:23:52 -0700 (PDT) In-Reply-To: <070E17B9-F989-4184-A702-7D323710F52B@inria.fr> References: <070E17B9-F989-4184-A702-7D323710F52B@inria.fr> From: Gabriel Cardoso Date: Tue, 13 Mar 2012 13:23:52 +0100 Message-ID: To: Samuel Hornus Cc: caml-list Content-Type: multipart/alternative; boundary=f46d043086c06cb97d04bb1ef0f8 Subject: Re: [Caml-list] Problem with Arg.Tuple --f46d043086c06cb97d04bb1ef0f8 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Thanks, I get it now ! Cheers Gabriel 2012/3/13 Samuel Hornus > > On Mar13, 2012, at 11:49 , Gabriel Cardoso wrote: > > > Dear list, > > > > I have empty arguments when using Arg.Tuple with references. This > minimalist example illustrates my problem : > > > > let f a b =3D > > print_endline a; > > print_endline b > > > > let s =3D ref "" > > > > let speclist =3D [( > > "-a", > > Arg.Tuple [ > > Arg.Set_string s; > > Arg.String (f !s) (* !s is empty !!! *) > > Here, the value of !s is empty when the (f !s) is evaluated=85 > you shoud pass the whole reference as argument : > Arg.String(f s) > and > let f a b =3D print_endline !a; print_endline b > > > (* Arg.String (fun ss -> f !s ss) (\* Works just fine ... why ? *\) > *) > > why ? because the !s here is evaluated only later, whenthe anonymous > function is applied. > -- > Sam --f46d043086c06cb97d04bb1ef0f8 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Thanks, I get it now !

Cheers

G= abriel

2012/3/13 Samuel Hornus <samuel.hornus@= inria.fr>

On Mar13, 2012, at 11:49 , Gabriel Cardoso wrote:

> Dear list,
>
> I have empty arguments when using Arg.Tuple with references. This mini= malist example illustrates my problem :
>
> let f a b =3D
> =A0 print_endline a;
> =A0 print_endline b
>
> let s =3D ref ""
>
> let speclist =3D [(
> =A0 "-a",
> =A0 Arg.Tuple [
> =A0 =A0 Arg.Set_string s;
> =A0 =A0 Arg.String (f !s) (* !s is empty !!! *)

Here, the value of !s is empty when the (f !s) is evaluated=85
you shoud pass the whole reference as argument :
Arg.String(f s)
and
let f a b =3D print_endline !a; print_endline b

> =A0 =A0 (* Arg.String (fun ss -> f !s ss) (\* Works just fine ... w= hy ? *\) *)

why ? because the !s here is evaluated only later, whenthe anonymous = function is applied.
--
Sam

--f46d043086c06cb97d04bb1ef0f8--