ph.Cheers!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...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";;[pbil:~ 18:58]$ocaml rien.ml
#camlp4o;;
#require " sexplib.syntax";;
open Sexplib.Std;;
type t = int with sexp;;
File "rien.ml", line 12, characters 13-17:
Error: Syntax error
2014-07-01 18:51 GMT+02:00 David Sheets <sheets@alum.mit.edu>:
How does the first call fail? A difference between the two is that, inOn 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?
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