From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 75E4A7F9BB for ; Wed, 2 Jul 2014 16:49:00 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of philippe.veber@gmail.com) identity=pra; client-ip=74.125.82.51; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="philippe.veber@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of philippe.veber@gmail.com designates 74.125.82.51 as permitted sender) identity=mailfrom; client-ip=74.125.82.51; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="philippe.veber@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wg0-f51.google.com) identity=helo; client-ip=74.125.82.51; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="postmaster@mail-wg0-f51.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AloBAL0atFNKfVIzlGdsb2JhbABag19avQeJFQF/CBYPAQEBAQcLCwkSKoQDAQEBAwESFRkBGx0BAwELBgULBgMBAgEnByEBAREBBQELCQgGEyKICwEDCQiebmqNGYMQj00KGScNZIUlEQEFDoxsghcRBwaEPQWYboF/gUiMLoQjGCmEdTs X-IPAS-Result: AloBAL0atFNKfVIzlGdsb2JhbABag19avQeJFQF/CBYPAQEBAQcLCwkSKoQDAQEBAwESFRkBGx0BAwELBgULBgMBAgEnByEBAREBBQELCQgGEyKICwEDCQiebmqNGYMQj00KGScNZIUlEQEFDoxsghcRBwaEPQWYboF/gUiMLoQjGCmEdTs X-IronPort-AV: E=Sophos;i="5.01,588,1400018400"; d="scan'208";a="83329593" Received: from mail-wg0-f51.google.com ([74.125.82.51]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Jul 2014 16:48:59 +0200 Received: by mail-wg0-f51.google.com with SMTP id x12so11375150wgg.10 for ; Wed, 02 Jul 2014 07:48:59 -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=6O3spmwM5qXOiGsvC4Wo9sIGurEAcDlUGPHBKSne3ho=; b=kmrMzAvNK9scFwALkOGGVVgL7byEANHnQVKpThUmP/LZaw4n+Yv544zH5SgwudLL1d CA2tK/L0oFLq7L+RGzag1V7x5LAnGByqjByYPLbMvaYLgnhpBuWCB0fefxACCCmzR6MJ 2zzgCrvrgN0BS8aPXdYU+Q+qARo7gMR/ce3RHvFgnkzvv0p6jLhdu1Iqbau33JkhxdMo kSmAlEX/x2XV5iC8UMstE5er6inBbnsKzAeVXVpl6gHPBL5R65vS9C04A9sZy0PPLuMs NfopHvwGfK5ghzEw8oIXZ0g0cKs0RsuJL0Thj9IKw6HeZTncnvQ1iAGIQfemqsvzgFSY aCFQ== X-Received: by 10.180.72.38 with SMTP id a6mr44587821wiv.29.1404312539422; Wed, 02 Jul 2014 07:48:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.175.232 with HTTP; Wed, 2 Jul 2014 07:48:39 -0700 (PDT) In-Reply-To: <53B3F496.2020908@inria.fr> References: <53B3F496.2020908@inria.fr> From: Philippe Veber Date: Wed, 2 Jul 2014 16:48:39 +0200 Message-ID: To: Romain Bardou Cc: Fabrice Le Fessant , David Sheets , caml users Content-Type: multipart/alternative; boundary=001a11c2497810e8f904fd36fe80 X-Validation-by: philippe.veber@gmail.com Subject: Re: [Caml-list] Fwd: Toplevel and syntax extension. --001a11c2497810e8f904fd36fe80 Content-Type: text/plain; charset=ISO-8859-1 Thanks Romain, I'll rather use Fabrice's suggestion, which handles command-line argument more simply. Cheers, Philippe. 2014-07-02 14:01 GMT+02:00 Romain Bardou : > You could write a wrapper which start the ocaml process, sends a string > containing something like: > > module Sys = > struct > include Sys > let argv = ... (* fill this *) > end > > to the ocaml process (replace the ... by the arguments given to the > wrapper, using the array syntax, and don't forget that the first cell > must contain the executable path), and then pass the contents of your > script.ml. > > This does not work if your script uses other modules which themselves > use Sys.argv. > > Cheers, > > -- Romain Bardou > > On 02/07/2014 13:48, Philippe Veber wrote: > > Thanks Fabrice, this perfectly explains what I observe. Is this behavior > > considered the right one? Reading from a pipe is regretfully not an > > option for me, as my script has command line arguments. Hence when I > type: > > > > cat script.ml | ocaml --foo --bar 1 > > > > the toplevel complains it knows nothing about the arguments foo and bar. > > A "--" argument would be useful but it seems not available. If it's so, > > I'll file a feature request on Mantis, since without it, there seems to > > be no way to give a script to the toplevel that both takes command line > > arguments and uses a syntax extension. > > > > Thanks again! > > > > > > > > 2014-07-02 10:08 GMT+02:00 Fabrice Le Fessant > > >: > > > > If I remember well, I think "ocaml" has a different behavior > > depending on what it reads from: > > * From a pipe, it parses every sentence and execute each one > > immediatly. > > * From a file, it tries to parse the whole file, and then executes > > everything. > > > > In the second case, it means it will only execute the load of the > > syntax extension after parsing the whole file... which will fail, > > since the syntax extension is needed for that. > > > > --Fabrice > > INRIA & OCamlPro > > > > > > > > On Tue, Jul 1, 2014 at 7:06 PM, Philippe Veber > > > wrote: > > > > Thanks David! > > > > The first call fails with a syntax error on "with sexp": > > > > [pbil:~ 18:58]$cat rien.ml > > > > let () = > > try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH") > > with Not_found -> () > > ;; > > > > #use "topfind";; > > #camlp4o;; > > #require " sexplib.syntax";; > > > > open Sexplib.Std;; > > > > type t = int with sexp;; > > > > [pbil:~ 18:58]$ocaml rien.ml > > File "rien.ml ", line 12, characters 13-17: > > Error: Syntax error > > > > It seems like the sexp syntax extension is not loaded when the > > script is evaluated. But it's not really clear to me what going > > wrong... > > > > Cheers! > > ph. > > > > > > > > 2014-07-01 18:51 GMT+02:00 David Sheets > >: > > > > On Tue, Jul 1, 2014 at 5:38 PM, Philippe Veber > > > > > wrote: > > > Reposting this question here, just in case. > > > > > > ---------- Forwarded message ---------- > > > From: Philippe Veber > > > > > Date: 2014-06-28 21:32 GMT+02:00 > > > Subject: Toplevel and syntax extension. > > > To: ocaml_beginners@yahoogroups.com > > > > > > > > > > > Dear camlers, > > > > > > Consider the following script: > > > > > > #use "topfind";; > > > #camlp4o;; > > > #require "sexplib.syntax";; > > > > > > open Sexplib.Std;; > > > > > > type t = int with sexp;; > > > > > > Saved as script.ml , the simple call: > > > > > > ocaml script.ml > > > > > > fails while the call: > > > > > > cat script.ml | ocaml > > > > > > succeeds. Any idea how I could fix the first call? > > > > How does the first call fail? A difference between the two > > is that, in > > the second, the .ocamlinit file is used. If you are using > > opam with > > ocamlfind installed via it, this file will contain your > > Topdirs setup. > > You can try: > > > > let () = > > try Topdirs.dir_directory (Sys.getenv > "OCAML_TOPLEVEL_PATH") > > with Not_found -> () > > ;; > > > > at the top of your script (after hashbang but before > > directives). > > > > Hope this helps, > > > > David > > > > > > > > > > > > -- > > Fabrice LE FESSANT > > Chercheur en Informatique > > INRIA Paris Rocquencourt -- OCamlPro > > Programming Languages and Distributed Systems > > > > > > --001a11c2497810e8f904fd36fe80 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thanks Romain, I'll rather use Fabrice's= suggestion, which handles command-line argument more simply.

= Cheers,

=A0Philippe.

<= br>
2014-07-02 14:01 GMT+02:00 Romain Bardou <= romain.bardou@inria.fr>:
You could write a wrapper which start the ocaml process, sends a string
containing something like:

module Sys =3D
struct
=A0 include Sys
=A0 let argv =3D ... (* fill this *)
end

to the ocaml process (replace the ... by the arguments given to the
wrapper, using the array syntax, and don't forget that the first cell must contain the executable path), and then pass the contents of your
script.ml.

This does not work if your script uses other modules which themselves
use Sys.argv.

Cheers,

-- Romain Bardou

On 02/07/2014 13:48, Philippe Veber wrote:
> Thanks Fabrice, this perfectly explains what I observe. Is this behavi= or
> considered the right one? Reading from a pipe is regretfully not an
> option for me, as my script has command line arguments. Hence when I t= ype:
>
> cat script.ml= <http://script.ml>= ; | ocaml --foo --bar 1
>
> the toplevel complains it knows nothing about the arguments foo and ba= r.
> A "--" argument would be useful but it seems not available. = If it's so,
> I'll file a feature request on Mantis, since without it, there see= ms to
> be no way to give a script to the toplevel that both takes command lin= e
> arguments and uses a syntax extension.
>
> Thanks again!
>
>
>
> 2014-07-02 10:08 GMT+02:00 Fabrice Le Fessant
> <Fabrice.Le_fe= ssant@inria.fr <mailto:Fabrice.Le_fessant@inria.fr>>:
>
> =A0 =A0 If I remember well, I think "ocaml" has a different = behavior
> =A0 =A0 depending on what it reads from:
> =A0 =A0 * From a pipe, it parses every sentence and execute each one > =A0 =A0 immediatly.
> =A0 =A0 * From a file, it tries to parse the whole file, and then exec= utes
> =A0 =A0 everything.
>
> =A0 =A0 In the second case, it means it will only execute the load of = the
> =A0 =A0 syntax extension after parsing the whole file... which will fa= il,
> =A0 =A0 since the syntax extension is needed for that.
>
> =A0 =A0 --Fabrice
> =A0 =A0 INRIA & OCamlPro
>
>
>
> =A0 =A0 On Tue, Jul 1, 2014 at 7:06 PM, Philippe Veber
> =A0 =A0 <philippe.veber@gmail.com <mailto:philippe.veber@gmail.com>> wrote:
>
> =A0 =A0 =A0 =A0 Thanks David!
>
> =A0 =A0 =A0 =A0 The first call fails with a syntax error on "with= sexp":
>
> =A0 =A0 =A0 =A0 [pbil:~ 18:58]$cat rien.ml <http://rien.ml>
>
> =A0 =A0 =A0 =A0 let () =3D
> =A0 =A0 =A0 =A0 =A0 try Topdirs.dir_directory (Sys.getenv "OCAML_= TOPLEVEL_PATH")
> =A0 =A0 =A0 =A0 =A0 with Not_found -> ()
> =A0 =A0 =A0 =A0 ;;
>
> =A0 =A0 =A0 =A0 #use "topfind";;
> =A0 =A0 =A0 =A0 #camlp4o;;
> =A0 =A0 =A0 =A0 #require " sexplib.syntax";;
>
> =A0 =A0 =A0 =A0 open Sexplib.Std;;
>
> =A0 =A0 =A0 =A0 type t =3D int with sexp;;
>
> =A0 =A0 =A0 =A0 [pbil:~ 18:58]$ocaml rien.ml <http://rien.ml>
> =A0 =A0 =A0 =A0 File "rien.ml <http://rien.= ml>", line 12, characters 13-17:
> =A0 =A0 =A0 =A0 Error: Syntax error
>
> =A0 =A0 =A0 =A0 It seems like the sexp syntax extension is not loaded = when the
> =A0 =A0 =A0 =A0 script is evaluated. But it's not really clear to = me what going
> =A0 =A0 =A0 =A0 wrong...
>
> =A0 =A0 =A0 =A0 Cheers!
> =A0 =A0 =A0 =A0 ph.
>
>
>
> =A0 =A0 =A0 =A0 2014-07-01 18:51 GMT+02:00 David Sheets <sheets@alum.mit.edu
> =A0 =A0 =A0 =A0 <mailto:sheets@alum.mit.edu>>:
>
> =A0 =A0 =A0 =A0 =A0 =A0 On Tue, Jul 1, 2014 at 5:38 PM, Philippe Veber=
> =A0 =A0 =A0 =A0 =A0 =A0 <philippe.veber@gmail.com <mailto:philippe.veber@gmail.com>>
> =A0 =A0 =A0 =A0 =A0 =A0 wrote:
> =A0 =A0 =A0 =A0 =A0 =A0 > Reposting this question here, just in cas= e.
> =A0 =A0 =A0 =A0 =A0 =A0 >
> =A0 =A0 =A0 =A0 =A0 =A0 > ---------- Forwarded message ---------- > =A0 =A0 =A0 =A0 =A0 =A0 > From: Philippe Veber <philippe.veber@gmail.com
> =A0 =A0 =A0 =A0 =A0 =A0 <mailto:philippe.veber@gmail.com>>
> =A0 =A0 =A0 =A0 =A0 =A0 > Date: 2014-06-28 21:32 GMT+02:00
> =A0 =A0 =A0 =A0 =A0 =A0 > Subject: Toplevel and syntax extension. > =A0 =A0 =A0 =A0 =A0 =A0 > To: ocaml_beginners@yahoogroups.com
> =A0 =A0 =A0 =A0 =A0 =A0 <mailto:ocaml_beginners@yahoogroups.com&g= t;
> =A0 =A0 =A0 =A0 =A0 =A0 >
> =A0 =A0 =A0 =A0 =A0 =A0 >
> =A0 =A0 =A0 =A0 =A0 =A0 > Dear camlers,
> =A0 =A0 =A0 =A0 =A0 =A0 >
> =A0 =A0 =A0 =A0 =A0 =A0 > Consider the following script:
> =A0 =A0 =A0 =A0 =A0 =A0 >
> =A0 =A0 =A0 =A0 =A0 =A0 > #use "topfind";;
> =A0 =A0 =A0 =A0 =A0 =A0 > #camlp4o;;
> =A0 =A0 =A0 =A0 =A0 =A0 > #require "sexplib.syntax";;
> =A0 =A0 =A0 =A0 =A0 =A0 >
> =A0 =A0 =A0 =A0 =A0 =A0 > open Sexplib.Std;;
> =A0 =A0 =A0 =A0 =A0 =A0 >
> =A0 =A0 =A0 =A0 =A0 =A0 > type t =3D int with sexp;;
> =A0 =A0 =A0 =A0 =A0 =A0 >
> =A0 =A0 =A0 =A0 =A0 =A0 > Saved as script.ml <http://script.ml>, the simple call:
> =A0 =A0 =A0 =A0 =A0 =A0 >
> =A0 =A0 =A0 =A0 =A0 =A0 > ocaml script.ml <http://script.ml>
> =A0 =A0 =A0 =A0 =A0 =A0 >
> =A0 =A0 =A0 =A0 =A0 =A0 > fails while the call:
> =A0 =A0 =A0 =A0 =A0 =A0 >
> =A0 =A0 =A0 =A0 =A0 =A0 > cat script.ml <http://script.ml> | ocaml
> =A0 =A0 =A0 =A0 =A0 =A0 > > =A0 =A0 =A0 =A0 =A0 =A0 > succeeds. Any idea how I could fix the fi= rst call?
>
> =A0 =A0 =A0 =A0 =A0 =A0 How does the first call fail? A difference bet= ween the two
> =A0 =A0 =A0 =A0 =A0 =A0 is that, in
> =A0 =A0 =A0 =A0 =A0 =A0 the second, the .ocamlinit file is used. If yo= u are using
> =A0 =A0 =A0 =A0 =A0 =A0 opam with
> =A0 =A0 =A0 =A0 =A0 =A0 ocamlfind installed via it, this file will con= tain your
> =A0 =A0 =A0 =A0 =A0 =A0 Topdirs setup.
> =A0 =A0 =A0 =A0 =A0 =A0 You can try:
>
> =A0 =A0 =A0 =A0 =A0 =A0 let () =3D
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 try Topdirs.dir_directory (Sys.getenv &quo= t;OCAML_TOPLEVEL_PATH")
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 with Not_found -> ()
> =A0 =A0 =A0 =A0 =A0 =A0 ;;
>
> =A0 =A0 =A0 =A0 =A0 =A0 at the top of your script (after hashbang but = before
> =A0 =A0 =A0 =A0 =A0 =A0 directives).
>
> =A0 =A0 =A0 =A0 =A0 =A0 Hope this helps,
>
> =A0 =A0 =A0 =A0 =A0 =A0 David
>
>
>
>
>
> =A0 =A0 --
> =A0 =A0 Fabrice LE FESSANT
> =A0 =A0 Chercheur en Informatique
> =A0 =A0 INRIA Paris Rocquencourt -- OCamlPro
> =A0 =A0 Programming Languages and Distributed Systems
>
>


--001a11c2497810e8f904fd36fe80--