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 575737F9BB for ; Wed, 2 Jul 2014 13:59:58 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of romain.bardou@inria.fr) identity=pra; client-ip=178.32.119.250; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="romain.bardou@inria.fr"; x-sender="romain.bardou@inria.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of romain.bardou@inria.fr) identity=mailfrom; client-ip=178.32.119.250; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="romain.bardou@inria.fr"; x-sender="romain.bardou@inria.fr"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mo1.mail-out.ovh.net) identity=helo; client-ip=178.32.119.250; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="romain.bardou@inria.fr"; x-sender="postmaster@mo1.mail-out.ovh.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkQBAA70s1OyIHf6nGdsb2JhbABag1/GdwEHgRsPAQEBAQEICwkJFCiEAwEBBAEnUQEFCwsRAwECAQkWCAcJAwIBAgEPJQkIBgEMAQUCAogqAwkMAb9lDYYJF4x6gXUzBwYohBUBBJhtAYF/gUiFboY/iVk X-IPAS-Result: AkQBAA70s1OyIHf6nGdsb2JhbABag1/GdwEHgRsPAQEBAQEICwkJFCiEAwEBBAEnUQEFCwsRAwECAQkWCAcJAwIBAgEPJQkIBgEMAQUCAogqAwkMAb9lDYYJF4x6gXUzBwYohBUBBJhtAYF/gUiFboY/iVk X-IronPort-AV: E=Sophos;i="5.01,587,1400018400"; d="scan'208";a="83296116" Received: from 2.mo1.mail-out.ovh.net (HELO mo1.mail-out.ovh.net) ([178.32.119.250]) by mail2-smtp-roc.national.inria.fr with ESMTP; 02 Jul 2014 13:59:57 +0200 Received: from mail98.ha.ovh.net (gw6.ovh.net [213.251.189.206]) by mo1.mail-out.ovh.net (Postfix) with SMTP id 3FDBEFF9CD7 for ; Wed, 2 Jul 2014 13:59:57 +0200 (CEST) Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 2 Jul 2014 13:59:57 +0200 Received: from unknown (HELO ?10.1.202.10?) (postmaster@doomeer.com@194.254.61.161) by ns0.ovh.net with SMTP; 2 Jul 2014 13:59:53 +0200 Message-ID: <53B3F496.2020908@inria.fr> Date: Wed, 02 Jul 2014 14:01:26 +0200 From: Romain Bardou User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.5.0 MIME-Version: 1.0 To: Philippe Veber , Fabrice Le Fessant CC: David Sheets , caml users References: In-Reply-To: X-Enigmail-Version: 1.6+git0.20140323 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Ovh-Tracer-Id: 17598097021051963957 X-Ovh-Remote: 194.254.61.161 () X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-OVH-SPAMSTATE: OK X-OVH-SPAMSCORE: -100 X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeejfedrudefucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-Spam-Check: DONE|U 0.5/N X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeejfedrudefucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-Validation-by: romain@bardou.fr Subject: Re: [Caml-list] Fwd: Toplevel and syntax extension. 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 > >