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 701177F9BB for ; Wed, 2 Jul 2014 16:46:38 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of philippe.veber@gmail.com) identity=pra; client-ip=209.85.212.182; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="philippe.veber@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of philippe.veber@gmail.com designates 209.85.212.182 as permitted sender) identity=mailfrom; client-ip=209.85.212.182; receiver=mail3-smtp-sop.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 (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f182.google.com) identity=helo; client-ip=209.85.212.182; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="postmaster@mail-wi0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao0BAL0atFPRVdS2m2dsb2JhbABag19armCOJ4kVAX8IFg8BAQEBAQYLCwkUKIQDAQEBAwESFRkBGx0BAwELBgULBgMBAgEuIQEBEQEFARQIBhMIGogLAQMJCJ5uao0ZgxCPTQoZJw1khSURAQUOjGyCFxEHBoQ9BZhugX+BSIwuhCMYKYR1Ow X-IPAS-Result: Ao0BAL0atFPRVdS2m2dsb2JhbABag19armCOJ4kVAX8IFg8BAQEBAQYLCwkUKIQDAQEBAwESFRkBGx0BAwELBgULBgMBAgEuIQEBEQEFARQIBhMIGogLAQMJCJ5uao0ZgxCPTQoZJw1khSURAQUOjGyCFxEHBoQ9BZhugX+BSIwuhCMYKYR1Ow X-IronPort-AV: E=Sophos;i="5.01,588,1400018400"; d="scan'208";a="69902264" Received: from mail-wi0-f182.google.com ([209.85.212.182]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Jul 2014 16:46:35 +0200 Received: by mail-wi0-f182.google.com with SMTP id bs8so612559wib.15 for ; Wed, 02 Jul 2014 07:46:33 -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=2CJF2mu/kzFblrY5csKDbZjOJjxF3t6UkcB78P7RAuw=; b=CVnmTBAapzB7wf8rBoO57SeHsPhy5lyXuQgpxaLEhcaMDtCTifJjh0GSy9P+0S2S5n uut7JHSVcTsWTZQbpx9/c+k0ZNFJmeWLJPlCSWaW5vGxezwuAktLKOherG+dl+iSwWYn TytjXnPfosULDXiqVN54L/4MAMEVZV8tw5kEmr1RA7kljXggl2Gac79jvQveFe9mmzGo MNhgBbsiQlEw98t1rZzJZoc3kUNYZlsqIJ1AriF6ZS953XAA+fXE4aDK61myDdvMdano ATAm2JwYwqfQ3S8LRIxbgbU+caj117aSyLx9E3YdnzKt1m7qihtdSzZRJNmSKTQpPnjI 5fkQ== X-Received: by 10.180.10.98 with SMTP id h2mr4895582wib.29.1404312393323; Wed, 02 Jul 2014 07:46:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.175.232 with HTTP; Wed, 2 Jul 2014 07:46:13 -0700 (PDT) In-Reply-To: References: From: Philippe Veber Date: Wed, 2 Jul 2014 16:46:13 +0200 Message-ID: To: Fabrice Le Fessant Cc: David Sheets , caml users Content-Type: multipart/alternative; boundary=001a11c26a8a5bc11004fd36f5d9 X-Validation-by: philippe.veber@gmail.com Subject: Re: [Caml-list] Fwd: Toplevel and syntax extension. --001a11c26a8a5bc11004fd36f5d9 Content-Type: text/plain; charset=ISO-8859-1 Indeed, that works well (I wouldn't have thought so!) and is definitely not (too) cumbersome. Thanks! 2014-07-02 14:51 GMT+02:00 Fabrice Le Fessant : > 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 < >> Fabrice.Le_fessant@inria.fr>: >> >> 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 < >>>>> philippe.veber@gmail.com> 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 > --001a11c26a8a5bc11004fd36f5d9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Indeed, that works well (I wouldn't have thought so!) = and is definitely not (too) cumbersome. Thanks!


2014-07-02 14:51 GMT+02:00 Fabr= ice Le Fessant <Fabrice.Le_fessant@inria.fr>:
You might want to spli= t your file in two different files, a loader and the body:

=A0peerocaml:~% =A0cat > script_body.ml
open Sexplib.Std;;=
type t =3D int with sexp;;
=A0peerocaml:~% =A0cat >= script.ml
#use "topfind";;
#camlp4o;;
#req= uire "sexplib.syntax";;
=A0peerocaml:~% =A0ocaml script.ml=A0

--= Fabrice
INRIA & 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= :=A0
* From a pipe, it parses every sentence and execute each one immediatly.=A0=
* From a file, it tries to parse the whole file, and then execut= es 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
=A0 try Topdirs.dir_directory (Sys.getenv "= OCAML_TOPLEVEL_PATH")
=A0 with Not_found -> ()
;;

#use "topfind"= ;;;
#camlp4o;;
#require " sexplib.syntax";;

open Sex= plib.Std;;

type t =3D int with sexp;;

[pbil:~ 18:58]$oc= aml 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.
=A0


2014-07-01 18:51 GM= T+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
=A0 try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")<= br> =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

--001a11c26a8a5bc11004fd36f5d9--