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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id F00367F9BB for ; Wed, 2 Jul 2014 17:20:50 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of agarwal1975@gmail.com) identity=pra; client-ip=209.85.192.47; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="agarwal1975@gmail.com"; x-sender="agarwal1975@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of agarwal1975@gmail.com designates 209.85.192.47 as permitted sender) identity=mailfrom; client-ip=209.85.192.47; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="agarwal1975@gmail.com"; x-sender="agarwal1975@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qg0-f47.google.com) identity=helo; client-ip=209.85.192.47; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="agarwal1975@gmail.com"; x-sender="postmaster@mail-qg0-f47.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnkBAA8itFPRVcAvlGdsb2JhbABag19agm6oUwEGkT+JFQF/CBYPAQEBAQcLCwkSKoQDAQEBAwESEQQZARsdAQMBCwYDAgsGAwECAScDAgIhAQERAQUBCwkIBhMiiAsBAwkIjmyQFmqLJ4FygxCPTwoZJw1khSURAQUOhWKHCoIXEQcGgnGBTAEEmG6Bf4FIjC6EIxgphQ8h X-IPAS-Result: AnkBAA8itFPRVcAvlGdsb2JhbABag19agm6oUwEGkT+JFQF/CBYPAQEBAQcLCwkSKoQDAQEBAwESEQQZARsdAQMBCwYDAgsGAwECAScDAgIhAQERAQUBCwkIBhMiiAsBAwkIjmyQFmqLJ4FygxCPTwoZJw1khSURAQUOhWKHCoIXEQcGgnGBTAEEmG6Bf4FIjC6EIxgphQ8h X-IronPort-AV: E=Sophos;i="5.01,588,1400018400"; d="scan'208";a="69907104" Received: from mail-qg0-f47.google.com ([209.85.192.47]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Jul 2014 17:20:49 +0200 Received: by mail-qg0-f47.google.com with SMTP id q108so4782832qgd.20 for ; Wed, 02 Jul 2014 08:20:48 -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=KgJjeo6swWoDb+Qeyt9eD2hCP5waF6x43T9BQk9wmHY=; b=ZbEX1V6wpbZ/M6W5vHe7anc7nrobZhi7gSahLG3oyiZzAjcqBCmkZaYiYUzMYj0L1e 1rg5RgI+mTtD5wMvDxrCEMLW+0S9LK+WiVEn68wtXoprNhk4h1z3zsja8d6KU4dUpiSV 34o2NCHSFVtn7IYEMni10kZY2lFfSGHqH33T2gyhCWzRKOq0hft/LHA83YcSY1GD9bvR ZPnVp2DracZQydkheDMKlV+P/rSkWPshx3929E4M4KH99JfUjPjgSaMbXVmuMMhA6iZj Z9B3TLICCnp3sWc71MvYvwYJGd2EVKvhZgmajNFqLYXOtepw8x+qwtH+xCWn+bfyA+Vh +Dbg== X-Received: by 10.140.48.161 with SMTP id o30mr81355745qga.68.1404314448446; Wed, 02 Jul 2014 08:20:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.133.78 with HTTP; Wed, 2 Jul 2014 08:20:28 -0700 (PDT) In-Reply-To: References: <53B3F496.2020908@inria.fr> From: Ashish Agarwal Date: Wed, 2 Jul 2014 11:20:28 -0400 Message-ID: To: Philippe Veber Cc: Romain Bardou , Fabrice Le Fessant , David Sheets , caml users Content-Type: multipart/alternative; boundary=001a1135086eda4a1a04fd376f93 Subject: Re: [Caml-list] Fwd: Toplevel and syntax extension. --001a1135086eda4a1a04fd376f93 Content-Type: text/plain; charset=UTF-8 Yet another option is to use ocamlscript. The following works: $ cat script.ml #! /usr/bin/env ocamlscript Ocaml.ocamlflags := ["-thread"]; Ocaml.packs := ["sexplib.syntax"] -- open Sexplib.Std type t = int with sexp $ ./script.ml (* compiles without error *) On Wed, Jul 2, 2014 at 10:48 AM, Philippe Veber wrote: > 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 >> > >> > >> >> > --001a1135086eda4a1a04fd376f93 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable (* compiles without error *)




On Wed, Jul 2, 2014 at 10:48 AM, Philipp= e Veber <philippe.veber@gmail.com> wrote:
Thanks Romain, I'll rather use Fabrice's= suggestion, which handles command-line argument more simply.

= Cheers,

=C2=A0Philippe.

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
=C2=A0 include Sys
=C2=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_fessant@inria.fr <mailto:Fabrice.Le_fessant@inria.fr>&g= t;:
>
> =C2=A0 =C2=A0 If I remember well, I think "ocaml" has a diff= erent behavior
> =C2=A0 =C2=A0 depending on what it reads from:
> =C2=A0 =C2=A0 * From a pipe, it parses every sentence and execute each= one
> =C2=A0 =C2=A0 immediatly.
> =C2=A0 =C2=A0 * From a file, it tries to parse the whole file, and the= n executes
> =C2=A0 =C2=A0 everything.
>
> =C2=A0 =C2=A0 In the second case, it means it will only execute the lo= ad of the
> =C2=A0 =C2=A0 syntax extension after parsing the whole file... which w= ill fail,
> =C2=A0 =C2=A0 since the syntax extension is needed for that.
>
> =C2=A0 =C2=A0 --Fabrice
> =C2=A0 =C2=A0 INRIA & OCamlPro
>
>
>
> =C2=A0 =C2=A0 On Tue, Jul 1, 2014 at 7:06 PM, Philippe Veber
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 [pbil:~ 18:58]$cat rien.ml <http://rien.ml>
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 let () =3D
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 try Topdirs.dir_directory (Sys.gete= nv "OCAML_TOPLEVEL_PATH")
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 with Not_found -> ()
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;;
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 #use "topfind";;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 #camlp4o;;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 #require " sexplib.syntax";;
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 open Sexplib.Std;;
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 type t =3D int with sexp;;
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 [pbil:~ 18:58]$ocaml rien.ml <http://rien.ml>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 File "rien.ml <= http://rien.ml>", line 12, characters 13-17:
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 Error: Syntax error
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 It seems like the sexp syntax extension is= not loaded when the
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 script is evaluated. But it's not real= ly clear to me what going
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 wrong...
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 Cheers!
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 ph.
>
>
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 2014-07-01 18:51 GMT+02:00 David Sheets &l= t;sheets@alum.mit.= edu
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 <mailto:sheets@alum.mit.edu>>:
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 On Tue, Jul 1, 2014 at 5:38 = PM, Philippe Veber
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <philippe.veber@gmail.com &l= t;mailto:phil= ippe.veber@gmail.com>>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 wrote:
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > Reposting this question= here, just in case.
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > ---------- Forwarded me= ssage ----------
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > From: Philippe Veber &l= t;philippe.ve= ber@gmail.com
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <mailto:philippe.veber@gmai= l.com>>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > Date: 2014-06-28 21:32 = GMT+02:00
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > Subject: Toplevel and s= yntax extension.
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > To: ocaml_beginners@yahoogrou= ps.com
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <mailto:ocaml_beginn= ers@yahoogroups.com>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > Dear camlers,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > Consider the following = script:
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > #use "topfind"= ;;;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > #camlp4o;;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > #require "sexplib.= syntax";;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > open Sexplib.Std;;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > type t =3D int with sex= p;;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > Saved as script.ml <http://script.ml>, the simple call:
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > ocaml script.ml <http://script.ml>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > fails while the call: > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > cat script.ml <http://script.ml> | ocaml
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 >
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 > succeeds. Any idea how = I could fix the first call?
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 How does the first call fail= ? A difference between the two
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 is that, in
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 the second, the .ocamlinit f= ile is used. If you are using
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 opam with
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ocamlfind installed via it, = this file will contain your
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Topdirs setup.
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 You can try:
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 let () =3D
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 try Topdirs.dir_direc= tory (Sys.getenv "OCAML_TOPLEVEL_PATH")
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 with Not_found -> = ()
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;;
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 at the top of your script (a= fter hashbang but before
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 directives).
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Hope this helps,
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 David
>
>
>
>
>
> =C2=A0 =C2=A0 --
> =C2=A0 =C2=A0 Fabrice LE FESSANT
> =C2=A0 =C2=A0 Chercheur en Informatique
> =C2=A0 =C2=A0 INRIA Paris Rocquencourt -- OCamlPro
> =C2=A0 =C2=A0 Programming Languages and Distributed Systems
>
>



--001a1135086eda4a1a04fd376f93--