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 6B9F27F9BB for ; Wed, 2 Jul 2014 14:51:50 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of fabrissimo@gmail.com) identity=pra; client-ip=209.85.192.45; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="fabrissimo@gmail.com"; x-sender="fabrissimo@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of fabrissimo@gmail.com designates 209.85.192.45 as permitted sender) identity=mailfrom; client-ip=209.85.192.45; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="fabrissimo@gmail.com"; x-sender="fabrissimo@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-qg0-f45.google.com) identity=helo; client-ip=209.85.192.45; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="fabrissimo@gmail.com"; x-sender="postmaster@mail-qg0-f45.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsUBAIz/s1PRVcAtlGdsb2JhbABag19agm6rc44niRWBBQgWDwEBAQEHCwsJEiqEAwEBAQMBEhEEGQE4AQMBCwEFBQsGAwECASoCAiEBEgEFARQIBhMiiAwDCQiePWqLJ4UCj3EnDYYJEQEFDoxsghcegnGBTAWYboF/gUiMLQKEIRgpgWqDCzs X-IPAS-Result: AsUBAIz/s1PRVcAtlGdsb2JhbABag19agm6rc44niRWBBQgWDwEBAQEHCwsJEiqEAwEBAQMBEhEEGQE4AQMBCwEFBQsGAwECASoCAiEBEgEFARQIBhMiiAwDCQiePWqLJ4UCj3EnDYYJEQEFDoxsghcegnGBTAWYboF/gUiMLQKEIRgpgWqDCzs X-IronPort-AV: E=Sophos;i="5.01,587,1400018400"; d="scan'208";a="83307093" Received: from mail-qg0-f45.google.com ([209.85.192.45]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Jul 2014 14:51:49 +0200 Received: by mail-qg0-f45.google.com with SMTP id a108so4553039qge.4 for ; Wed, 02 Jul 2014 05:51:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=gIeneKyC06gbXB/M2LFbos2QwB/lL+Lu14/NRqRLFeM=; b=Q1Pf1bA/wjO1g4ip+iYKclEcHCZO835YnLvy5PqagUqlHT8geMp6Rq0pi6ffwIHbfa lRMkmqfVfFrLR5g5Rj5R9M9VOA+tibso/xQCzgk5KU6I9twspVXJ+0DcX6xnoXUtoErL EjBLdNxT0G7UIsMZ1eY+G0vtllwGz2WKcLB9y1RZgF312VWl5W7E621AEc5O4YMUEp5p hfMHZAiYugpJO31MS8W/tuljZwotmwIHtlKWk9oApDtSolRKFIrouZp/XIufNOMbXAz6 nV13JAm9IpaFZ6VIJKVaFJtkn56Yfg/T4bT0QAp+wmS9EiXC5MijrDXkySrSlluxY3oh skKw== MIME-Version: 1.0 X-Received: by 10.224.136.200 with SMTP id s8mr6185161qat.85.1404305508509; Wed, 02 Jul 2014 05:51:48 -0700 (PDT) Sender: fabrissimo@gmail.com Received: by 10.96.63.136 with HTTP; Wed, 2 Jul 2014 05:51:48 -0700 (PDT) In-Reply-To: References: Date: Wed, 2 Jul 2014 14:51:48 +0200 X-Google-Sender-Auth: BNLkyxwpKui6VCKZ7zmf1lz3rKM Message-ID: From: Fabrice Le Fessant To: Philippe Veber Cc: David Sheets , caml users Content-Type: multipart/alternative; boundary=001a11c2caa2fdaed204fd355a01 Subject: Re: [Caml-list] Fwd: Toplevel and syntax extension. --001a11c2caa2fdaed204fd355a01 Content-Type: text/plain; charset=UTF-8 You might want to split your file in two different files, a loader and the body: peerocaml:~% cat > script_body.ml open Sexplib.Std;; type t = int with sexp;; peerocaml:~% cat > script.ml #use "topfind";; #camlp4o;; #require "sexplib.syntax";; #use "script_body.ml" peerocaml:~% ocaml script.ml --Fabrice INRIA & OCamlPro On Wed, Jul 2, 2014 at 1:48 PM, 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 >> > > -- Fabrice LE FESSANT Chercheur en Informatique INRIA Paris Rocquencourt -- OCamlPro Programming Languages and Distributed Systems --001a11c2caa2fdaed204fd355a01 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
You might want to split your file in two different fi= les, a loader and the body:

=C2=A0peerocaml:~% =C2= =A0cat > script_body.ml
= open Sexplib.Std;;
type t =3D int with sexp;;
=C2=A0peerocaml:~% =C2=A0cat >= script.ml
#use "topfind&qu= ot;;;
#camlp4o;;
#require "sexplib.syntax";;<= /div>=
=C2=A0peerocaml:~% =C2=A0ocaml scrip= t.ml=C2=A0

--Fabrice
INRIA &am= p; OCamlPro




On Wed, Jul 2, 2014 at 1:48 PM, Philippe Veber <philippe.veber@gmail.com> wrote:
Thanks Fabrice, t= his perfectly explains what I observe. Is this behavior considered the righ= t one? Reading from a pipe is regretfully not an option for me, as my scrip= t 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 exten= sion.

Thanks again!

<= /div>


20= 14-07-02 10:08 GMT+02:00 Fabrice Le Fessant <Fabrice.Le_fessan= t@inria.fr>:

If I remember well, I think= "ocaml" has a different behavior depending on what it reads from= :=C2=A0
* From a pipe, it parses every sentence and execute each one immediatly.=C2= =A0
* From a file, it tries to parse the whole file, and then exe= cutes everything.

In the second case, it means it will only execute= the load of the syntax extension after parsing the whole file... which wil= l fail, since the syntax extension is needed for that.

--Fabrice
INRIA & OCamlPro



On Tue= , Jul 1, 2014 at 7:06 PM, Philippe Veber <philippe.veber@gmail.com<= /a>> wrote:
Thanks = David!

The first call fails with a syntax error on "with = sexp":

[pbil:~ 18:58]$cat
rien.ml=

let () =3D
=C2=A0 try Topdirs.dir_directory (Sys.getenv &qu= ot;OCAML_TOPLEVEL_PATH")
=C2=A0 with Not_found -> ()
;;

#use "topfind&q= uot;;;
#camlp4o;;
#require " sexplib.syntax";;

open = Sexplib.Std;;

type t =3D int with sexp;;

[pbil:~ 18:58]= $ocaml rien.ml
File "rien.ml", = line 12, characters 13-17:
Error: Syntax error

It seems lik= e 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.
=C2=A0


2014-07-01 18:51= GMT+02:00 David Sheets <sheets@alum.mit.edu>:

On Tue, Jul 1, 2014 at 5:38 PM, Ph= ilippe Veber <philippe.veber@gmail.com> wrote:
> Reposting this question here, just in case.
>
> ---------- Forwarded message ----------
> From: Philippe Veber <philippe.veber@gmail.com>
> 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 =3D int with sexp;;
>
> Saved as script.ml,= the simple call:
>
> ocaml script.ml
>
> fails while the call:
>
> cat script.ml | oca= ml
>
> succeeds. Any idea how I could fix the first call?

How does the first call fail? A difference between the two is t= hat, 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 () =3D
=C2=A0 try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH"= ;)
=C2=A0 with Not_found -> ()
;;

at the top of your script (after hashbang but before directives).

Hope this helps,

David




<= font color=3D"#888888">--
Fabrice LE FESSANT
Chercheur en Informatiq= ue
INRIA Paris Rocquencourt -- OCamlPro
Programming Languages and Dis= tributed Systems




--
Fabrice LE F= ESSANT
Chercheur en Informatique
INRIA Paris Rocquencourt -- OCamlPro=
Programming Languages and Distributed Systems --001a11c2caa2fdaed204fd355a01--