caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Philippe Veber <philippe.veber@gmail.com>
To: Fabrice Le Fessant <Fabrice.Le_fessant@inria.fr>
Cc: David Sheets <sheets@alum.mit.edu>, caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Fwd: Toplevel and syntax extension.
Date: Wed, 2 Jul 2014 13:48:24 +0200	[thread overview]
Message-ID: <CAOOOohSGzGuxghCE2sZH7aK8AZ+Ah1o26=rHBsom+AtR7F3Wow@mail.gmail.com> (raw)
In-Reply-To: <CAHvkLrMx8eRG8Zn3LXcTMoA4+SX60+ZQnKc9cakv1uo0_CaFwQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3379 bytes --]

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 <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 () =
>>   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 <sheets@alum.mit.edu>:
>>
>> 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 <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 = 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
>

[-- Attachment #2: Type: text/html, Size: 5539 bytes --]

  reply	other threads:[~2014-07-02 11:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAOOOohTxesz1QpzFYO5RvjwpwRbuRJ_wKvYsYOqb23FsYKDVQg@mail.gmail.com>
2014-07-01 16:38 ` Philippe Veber
2014-07-01 16:51   ` David Sheets
2014-07-01 17:06     ` Philippe Veber
2014-07-02  8:08       ` Fabrice Le Fessant
2014-07-02 11:48         ` Philippe Veber [this message]
2014-07-02 12:01           ` Romain Bardou
2014-07-02 14:48             ` Philippe Veber
2014-07-02 15:20               ` Ashish Agarwal
2014-07-03  6:16                 ` Philippe Veber
2014-07-02 12:51           ` Fabrice Le Fessant
2014-07-02 14:46             ` Philippe Veber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOOOohSGzGuxghCE2sZH7aK8AZ+Ah1o26=rHBsom+AtR7F3Wow@mail.gmail.com' \
    --to=philippe.veber@gmail.com \
    --cc=Fabrice.Le_fessant@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=sheets@alum.mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).