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 406A17F9BB for ; Wed, 2 Jul 2014 13:48:47 +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=209.85.213.53; 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 209.85.213.53 as permitted sender) identity=mailfrom; client-ip=209.85.213.53; 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-yh0-f53.google.com) identity=helo; client-ip=209.85.213.53; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="postmaster@mail-yh0-f53.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am0BAIjws1PRVdU1m2dsb2JhbABag19avQiJFQGBBAgWDwEBAQEBBgsLCRQohAMBAQEDARIVGQEbHQEDAQsGBQsGAwECAS4hAQERAQUBFAgGEyKICwEDCQieNWqNGYMQj1YKGScNZIUlEQEFDoxsghcRBwaEPQEEmG6Bf4FIjC0ChCEYKYR1Ow X-IPAS-Result: Am0BAIjws1PRVdU1m2dsb2JhbABag19avQiJFQGBBAgWDwEBAQEBBgsLCRQohAMBAQEDARIVGQEbHQEDAQsGBQsGAwECAS4hAQERAQUBFAgGEyKICwEDCQieNWqNGYMQj1YKGScNZIUlEQEFDoxsghcRBwaEPQEEmG6Bf4FIjC0ChCEYKYR1Ow X-IronPort-AV: E=Sophos;i="5.01,587,1400018400"; d="scan'208";a="83294433" Received: from mail-yh0-f53.google.com ([209.85.213.53]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Jul 2014 13:48:46 +0200 Received: by mail-yh0-f53.google.com with SMTP id b6so6721391yha.26 for ; Wed, 02 Jul 2014 04:48:45 -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=qi/LGVkc5mw3o7GcmVjLHOV6cmnV04jG6LhhIUso64s=; b=yVTt84tAfkZq/W7KQO00fLztvALwlXzZuGKNjUOGc87adGkbzwUIffs2vXyZyuCc9Y DFpsKSCvILj/pthOUBJhA1WrE/dpSts9FzwlwvOnjmwRguOj/GuAGLaMA2Qeu76eK7UD i98FM6swG+U4/vZllMzCod6KdsvbFFl8bQOLmieMHo0YCvRBghQkI+qRgnlx9u4LqUf3 9ClR8nzhxP4w6aDgpjrPoQuO0NNE/J87DYb2dbRfQn8MeAD0wJ58uJRZVQjZHfBmHDXg ATgQluKB2HmNxx4TLbzlZADaj43fPqW7jw45w8AQkiUND+R2pu0mUjzlrirB9CKzj+mn tD0A== X-Received: by 10.236.91.99 with SMTP id g63mr78431702yhf.6.1404301725030; Wed, 02 Jul 2014 04:48:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.170.42.202 with HTTP; Wed, 2 Jul 2014 04:48:24 -0700 (PDT) In-Reply-To: References: From: Philippe Veber Date: Wed, 2 Jul 2014 13:48:24 +0200 Message-ID: To: Fabrice Le Fessant Cc: David Sheets , caml users Content-Type: multipart/alternative; boundary=20cf3005e0d27a5ed004fd347979 X-Validation-by: philippe.veber@gmail.com Subject: Re: [Caml-list] Fwd: Toplevel and syntax extension. --20cf3005e0d27a5ed004fd347979 Content-Type: text/plain; charset=ISO-8859-1 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 > --20cf3005e0d27a5ed004fd347979 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thanks Fabrice, this perfectly explains what I o= bserve. Is this behavior considered the right one? Reading from a pipe is r= egretfully not an option for me, as my script has command line arguments. H= ence when I type:

cat script.ml | ocaml --foo --ba= r 1

the toplevel complains it knows nothing about the argument= s foo and bar. A "--" argument would be useful but it seems not a= vailable. 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!

<= /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.veb= er@gmail.com> 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




--
Fabrice LE FESSANT
Cherch= eur en Informatique
INRIA Paris Rocquencourt -- OCamlPro
Programming = Languages and Distributed Systems

--20cf3005e0d27a5ed004fd347979--