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 A7B937F9BB for ; Wed, 2 Jul 2014 10:08:21 +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.216.181; 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.216.181 as permitted sender) identity=mailfrom; client-ip=209.85.216.181; 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-qc0-f181.google.com) identity=helo; client-ip=209.85.216.181; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="fabrissimo@gmail.com"; x-sender="postmaster@mail-qc0-f181.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlkBAMG8s1PRVdi1m2dsb2JhbABag19agm66GIkVgQUIFg8BAQEBAQYLCwkUKIQDAQEBAwESEQQZATgBAwELAQUFCwYDAQIBKgICIQESAQUBFAgGEyKIDAMJCJ10aosnhQKPaScNhgkRAQUNjGuCFh6CcYFMBZhogX6BSIwphCEYKYFqgwo7 X-IPAS-Result: AlkBAMG8s1PRVdi1m2dsb2JhbABag19agm66GIkVgQUIFg8BAQEBAQYLCwkUKIQDAQEBAwESEQQZATgBAwELAQUFCwYDAQIBKgICIQESAQUBFAgGEyKIDAMJCJ10aosnhQKPaScNhgkRAQUNjGuCFh6CcYFMBZhogX6BSIwphCEYKYFqgwo7 X-IronPort-AV: E=Sophos;i="5.01,587,1400018400"; d="scan'208";a="83250345" Received: from mail-qc0-f181.google.com ([209.85.216.181]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Jul 2014 10:08:20 +0200 Received: by mail-qc0-f181.google.com with SMTP id x13so9379039qcv.40 for ; Wed, 02 Jul 2014 01:08:19 -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=2SC0N7xUvrsqfOujEG/rf2FwOGM8bKsXuUn0OskJvqA=; b=zYV+xWV3+Zg40i5x5TY3s/3miO+NbZgHovi5KvwmzMhaxHGa5d9uoReXkEQ0KPbjxo YjVin8DsKWCnTDw18SGzQSfG4raf+2SQDX7TCBGCr4EGMQvmWtKCJw2Ij4PkHIGvqrL3 xsvBl6W3iAtaXNSrBfKT2eOovPjZtj86bmUPmV+DW1BJt5rEGfsaRma13ABM45rDGWDP fpTONCcZciAHR5jckzTrplBkwjAeb970S3Jac7PRHbnY114NHPxIIVcTa3D/Sk5Mmcmn UDLI+PzTZbscXeyvBy1jTa655ZY+44gtIKz/ywFtSTGXGydNw1f0Cx5V//IkGlygVgZX v6EQ== MIME-Version: 1.0 X-Received: by 10.229.178.202 with SMTP id bn10mr78049750qcb.6.1404288499509; Wed, 02 Jul 2014 01:08:19 -0700 (PDT) Sender: fabrissimo@gmail.com Received: by 10.96.63.136 with HTTP; Wed, 2 Jul 2014 01:08:19 -0700 (PDT) In-Reply-To: References: Date: Wed, 2 Jul 2014 10:08:19 +0200 X-Google-Sender-Auth: fOABVkLHgIidRNlT6iY0a1M61rQ Message-ID: From: Fabrice Le Fessant To: Philippe Veber Cc: David Sheets , caml users Content-Type: multipart/alternative; boundary=001a11c2be922cf0a204fd3165ea Subject: Re: [Caml-list] Fwd: Toplevel and syntax extension. --001a11c2be922cf0a204fd3165ea Content-Type: text/plain; charset=UTF-8 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 --001a11c2be922cf0a204fd3165ea Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
If I remember well, I think "ocaml" has a differ= ent behavior depending on what it reads from:=C2=A0
* From a pipe, it p= arses every sentence and execute each one immediatly.=C2=A0
* Fro= m 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 wil= l fail, since the syntax extension is needed for that.

--Fabrice
INRIA & OCamlPro



On Tue, Jul 1, 2= 014 at 7:06 PM, Philippe Veber <philippe.veber@gmail.com> 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 "OCAML_TOPLEVEL_PATH")
=C2=A0 with Not_found -> ()
;;

#use &quo= t;topfind";;
#camlp4o;;
#require " sexplib.syntax";;
open Sexplib.Std;;

type t =3D int with sexp;;

[pb= il:~ 18:58]$ocaml rien.ml<= br> 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




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