* [Caml-list] Fwd: Toplevel and syntax extension. [not found] <CAOOOohTxesz1QpzFYO5RvjwpwRbuRJ_wKvYsYOqb23FsYKDVQg@mail.gmail.com> @ 2014-07-01 16:38 ` Philippe Veber 2014-07-01 16:51 ` David Sheets 0 siblings, 1 reply; 11+ messages in thread From: Philippe Veber @ 2014-07-01 16:38 UTC (permalink / raw) To: caml users [-- Attachment #1: Type: text/plain, Size: 567 bytes --] 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? Cheers, Philippe. [-- Attachment #2: Type: text/html, Size: 1192 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Fwd: Toplevel and syntax extension. 2014-07-01 16:38 ` [Caml-list] Fwd: Toplevel and syntax extension Philippe Veber @ 2014-07-01 16:51 ` David Sheets 2014-07-01 17:06 ` Philippe Veber 0 siblings, 1 reply; 11+ messages in thread From: David Sheets @ 2014-07-01 16:51 UTC (permalink / raw) To: Philippe Veber; +Cc: caml users 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 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Fwd: Toplevel and syntax extension. 2014-07-01 16:51 ` David Sheets @ 2014-07-01 17:06 ` Philippe Veber 2014-07-02 8:08 ` Fabrice Le Fessant 0 siblings, 1 reply; 11+ messages in thread From: Philippe Veber @ 2014-07-01 17:06 UTC (permalink / raw) To: David Sheets; +Cc: caml users [-- Attachment #1: Type: text/plain, Size: 1795 bytes --] 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 > [-- Attachment #2: Type: text/html, Size: 3016 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Fwd: Toplevel and syntax extension. 2014-07-01 17:06 ` Philippe Veber @ 2014-07-02 8:08 ` Fabrice Le Fessant 2014-07-02 11:48 ` Philippe Veber 0 siblings, 1 reply; 11+ messages in thread From: Fabrice Le Fessant @ 2014-07-02 8:08 UTC (permalink / raw) To: Philippe Veber; +Cc: David Sheets, caml users [-- Attachment #1: Type: text/plain, Size: 2574 bytes --] 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: 4307 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Fwd: Toplevel and syntax extension. 2014-07-02 8:08 ` Fabrice Le Fessant @ 2014-07-02 11:48 ` Philippe Veber 2014-07-02 12:01 ` Romain Bardou 2014-07-02 12:51 ` Fabrice Le Fessant 0 siblings, 2 replies; 11+ messages in thread From: Philippe Veber @ 2014-07-02 11:48 UTC (permalink / raw) To: Fabrice Le Fessant; +Cc: David Sheets, caml users [-- 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 --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Fwd: Toplevel and syntax extension. 2014-07-02 11:48 ` Philippe Veber @ 2014-07-02 12:01 ` Romain Bardou 2014-07-02 14:48 ` Philippe Veber 2014-07-02 12:51 ` Fabrice Le Fessant 1 sibling, 1 reply; 11+ messages in thread From: Romain Bardou @ 2014-07-02 12:01 UTC (permalink / raw) To: Philippe Veber, Fabrice Le Fessant; +Cc: David Sheets, caml users You could write a wrapper which start the ocaml process, sends a string containing something like: module Sys = struct include Sys let argv = ... (* fill this *) end to the ocaml process (replace the ... by the arguments given to the wrapper, using the array syntax, and don't forget that the first cell must contain the executable path), and then pass the contents of your script.ml. This does not work if your script uses other modules which themselves use Sys.argv. Cheers, -- Romain Bardou On 02/07/2014 13:48, 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 <http://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 <mailto: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 <mailto:philippe.veber@gmail.com>> wrote: > > Thanks David! > > The first call fails with a syntax error on "with sexp": > > [pbil:~ 18:58]$cat rien.ml <http://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 <http://rien.ml> > File "rien.ml <http://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 > <mailto:sheets@alum.mit.edu>>: > > On Tue, Jul 1, 2014 at 5:38 PM, Philippe Veber > <philippe.veber@gmail.com <mailto:philippe.veber@gmail.com>> > wrote: > > Reposting this question here, just in case. > > > > ---------- Forwarded message ---------- > > From: Philippe Veber <philippe.veber@gmail.com > <mailto:philippe.veber@gmail.com>> > > Date: 2014-06-28 21:32 GMT+02:00 > > Subject: Toplevel and syntax extension. > > To: ocaml_beginners@yahoogroups.com > <mailto: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 <http://script.ml>, the simple call: > > > > ocaml script.ml <http://script.ml> > > > > fails while the call: > > > > cat script.ml <http://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 > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Fwd: Toplevel and syntax extension. 2014-07-02 12:01 ` Romain Bardou @ 2014-07-02 14:48 ` Philippe Veber 2014-07-02 15:20 ` Ashish Agarwal 0 siblings, 1 reply; 11+ messages in thread From: Philippe Veber @ 2014-07-02 14:48 UTC (permalink / raw) To: Romain Bardou; +Cc: Fabrice Le Fessant, David Sheets, caml users [-- Attachment #1: Type: text/plain, Size: 5550 bytes --] Thanks Romain, I'll rather use Fabrice's suggestion, which handles command-line argument more simply. Cheers, Philippe. 2014-07-02 14:01 GMT+02:00 Romain Bardou <romain.bardou@inria.fr>: > You could write a wrapper which start the ocaml process, sends a string > containing something like: > > module Sys = > struct > include Sys > let argv = ... (* fill this *) > end > > to the ocaml process (replace the ... by the arguments given to the > wrapper, using the array syntax, and don't forget that the first cell > must contain the executable path), and then pass the contents of your > script.ml. > > This does not work if your script uses other modules which themselves > use Sys.argv. > > Cheers, > > -- Romain Bardou > > On 02/07/2014 13:48, 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 <http://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 <mailto: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 <mailto:philippe.veber@gmail.com>> wrote: > > > > Thanks David! > > > > The first call fails with a syntax error on "with sexp": > > > > [pbil:~ 18:58]$cat rien.ml <http://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 <http://rien.ml> > > File "rien.ml <http://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 > > <mailto:sheets@alum.mit.edu>>: > > > > On Tue, Jul 1, 2014 at 5:38 PM, Philippe Veber > > <philippe.veber@gmail.com <mailto:philippe.veber@gmail.com>> > > wrote: > > > Reposting this question here, just in case. > > > > > > ---------- Forwarded message ---------- > > > From: Philippe Veber <philippe.veber@gmail.com > > <mailto:philippe.veber@gmail.com>> > > > Date: 2014-06-28 21:32 GMT+02:00 > > > Subject: Toplevel and syntax extension. > > > To: ocaml_beginners@yahoogroups.com > > <mailto: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 <http://script.ml>, the simple call: > > > > > > ocaml script.ml <http://script.ml> > > > > > > fails while the call: > > > > > > cat script.ml <http://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: 8641 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Fwd: Toplevel and syntax extension. 2014-07-02 14:48 ` Philippe Veber @ 2014-07-02 15:20 ` Ashish Agarwal 2014-07-03 6:16 ` Philippe Veber 0 siblings, 1 reply; 11+ messages in thread From: Ashish Agarwal @ 2014-07-02 15:20 UTC (permalink / raw) To: Philippe Veber Cc: Romain Bardou, Fabrice Le Fessant, David Sheets, caml users [-- Attachment #1: Type: text/plain, Size: 6085 bytes --] Yet another option is to use ocamlscript. The following works: $ cat script.ml #! /usr/bin/env ocamlscript Ocaml.ocamlflags := ["-thread"]; Ocaml.packs := ["sexplib.syntax"] -- open Sexplib.Std type t = int with sexp $ ./script.ml (* compiles without error *) On Wed, Jul 2, 2014 at 10:48 AM, Philippe Veber <philippe.veber@gmail.com> wrote: > Thanks Romain, I'll rather use Fabrice's suggestion, which handles > command-line argument more simply. > > Cheers, > > Philippe. > > > 2014-07-02 14:01 GMT+02:00 Romain Bardou <romain.bardou@inria.fr>: > > You could write a wrapper which start the ocaml process, sends a string >> containing something like: >> >> module Sys = >> struct >> include Sys >> let argv = ... (* fill this *) >> end >> >> to the ocaml process (replace the ... by the arguments given to the >> wrapper, using the array syntax, and don't forget that the first cell >> must contain the executable path), and then pass the contents of your >> script.ml. >> >> This does not work if your script uses other modules which themselves >> use Sys.argv. >> >> Cheers, >> >> -- Romain Bardou >> >> On 02/07/2014 13:48, 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 <http://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 <mailto: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 <mailto:philippe.veber@gmail.com>> wrote: >> > >> > Thanks David! >> > >> > The first call fails with a syntax error on "with sexp": >> > >> > [pbil:~ 18:58]$cat rien.ml <http://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 <http://rien.ml> >> > File "rien.ml <http://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 >> > <mailto:sheets@alum.mit.edu>>: >> > >> > On Tue, Jul 1, 2014 at 5:38 PM, Philippe Veber >> > <philippe.veber@gmail.com <mailto:philippe.veber@gmail.com >> >> >> > wrote: >> > > Reposting this question here, just in case. >> > > >> > > ---------- Forwarded message ---------- >> > > From: Philippe Veber <philippe.veber@gmail.com >> > <mailto:philippe.veber@gmail.com>> >> > > Date: 2014-06-28 21:32 GMT+02:00 >> > > Subject: Toplevel and syntax extension. >> > > To: ocaml_beginners@yahoogroups.com >> > <mailto: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 <http://script.ml>, the simple call: >> > > >> > > ocaml script.ml <http://script.ml> >> > > >> > > fails while the call: >> > > >> > > cat script.ml <http://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: 10080 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Fwd: Toplevel and syntax extension. 2014-07-02 15:20 ` Ashish Agarwal @ 2014-07-03 6:16 ` Philippe Veber 0 siblings, 0 replies; 11+ messages in thread From: Philippe Veber @ 2014-07-03 6:16 UTC (permalink / raw) To: Ashish Agarwal Cc: Romain Bardou, Fabrice Le Fessant, David Sheets, caml users [-- Attachment #1: Type: text/plain, Size: 6597 bytes --] That's particularly neat! Not only does it work (I thought ocamlscript wouldn't accept syntax extensions, and did not even try), but also it gets me native code speed for free. Thanks Ashish (and Martin, of course)! 2014-07-02 17:20 GMT+02:00 Ashish Agarwal <agarwal1975@gmail.com>: > Yet another option is to use ocamlscript. The following works: > > $ cat script.ml > #! /usr/bin/env ocamlscript > Ocaml.ocamlflags := ["-thread"]; > Ocaml.packs := ["sexplib.syntax"] > -- > > open Sexplib.Std > type t = int with sexp > > $ ./script.ml > (* compiles without error *) > > > > > On Wed, Jul 2, 2014 at 10:48 AM, Philippe Veber <philippe.veber@gmail.com> > wrote: > >> Thanks Romain, I'll rather use Fabrice's suggestion, which handles >> command-line argument more simply. >> >> Cheers, >> >> Philippe. >> >> >> 2014-07-02 14:01 GMT+02:00 Romain Bardou <romain.bardou@inria.fr>: >> >> You could write a wrapper which start the ocaml process, sends a string >>> containing something like: >>> >>> module Sys = >>> struct >>> include Sys >>> let argv = ... (* fill this *) >>> end >>> >>> to the ocaml process (replace the ... by the arguments given to the >>> wrapper, using the array syntax, and don't forget that the first cell >>> must contain the executable path), and then pass the contents of your >>> script.ml. >>> >>> This does not work if your script uses other modules which themselves >>> use Sys.argv. >>> >>> Cheers, >>> >>> -- Romain Bardou >>> >>> On 02/07/2014 13:48, 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 <http://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 <mailto: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 <mailto:philippe.veber@gmail.com>> >>> wrote: >>> > >>> > Thanks David! >>> > >>> > The first call fails with a syntax error on "with sexp": >>> > >>> > [pbil:~ 18:58]$cat rien.ml <http://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 <http://rien.ml> >>> > File "rien.ml <http://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 >>> > <mailto:sheets@alum.mit.edu>>: >>> > >>> > On Tue, Jul 1, 2014 at 5:38 PM, Philippe Veber >>> > <philippe.veber@gmail.com <mailto:philippe.veber@gmail.com >>> >> >>> > wrote: >>> > > Reposting this question here, just in case. >>> > > >>> > > ---------- Forwarded message ---------- >>> > > From: Philippe Veber <philippe.veber@gmail.com >>> > <mailto:philippe.veber@gmail.com>> >>> > > Date: 2014-06-28 21:32 GMT+02:00 >>> > > Subject: Toplevel and syntax extension. >>> > > To: ocaml_beginners@yahoogroups.com >>> > <mailto: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 <http://script.ml>, the simple call: >>> > > >>> > > ocaml script.ml <http://script.ml> >>> > > >>> > > fails while the call: >>> > > >>> > > cat script.ml <http://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: 10343 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Fwd: Toplevel and syntax extension. 2014-07-02 11:48 ` Philippe Veber 2014-07-02 12:01 ` Romain Bardou @ 2014-07-02 12:51 ` Fabrice Le Fessant 2014-07-02 14:46 ` Philippe Veber 1 sibling, 1 reply; 11+ messages in thread From: Fabrice Le Fessant @ 2014-07-02 12:51 UTC (permalink / raw) To: Philippe Veber; +Cc: David Sheets, caml users [-- Attachment #1: Type: text/plain, Size: 4074 bytes --] 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 <philippe.veber@gmail.com> 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 <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 >> > > -- Fabrice LE FESSANT Chercheur en Informatique INRIA Paris Rocquencourt -- OCamlPro Programming Languages and Distributed Systems [-- Attachment #2: Type: text/html, Size: 6863 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Fwd: Toplevel and syntax extension. 2014-07-02 12:51 ` Fabrice Le Fessant @ 2014-07-02 14:46 ` Philippe Veber 0 siblings, 0 replies; 11+ messages in thread From: Philippe Veber @ 2014-07-02 14:46 UTC (permalink / raw) To: Fabrice Le Fessant; +Cc: David Sheets, caml users [-- Attachment #1: Type: text/plain, Size: 4440 bytes --] 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 <Fabrice.Le_fessant@inria.fr>: > 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 <philippe.veber@gmail.com> > 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 <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 >>> >> >> > > > -- > Fabrice LE FESSANT > Chercheur en Informatique > INRIA Paris Rocquencourt -- OCamlPro > Programming Languages and Distributed Systems > [-- Attachment #2: Type: text/html, Size: 7549 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2014-07-03 6:17 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <CAOOOohTxesz1QpzFYO5RvjwpwRbuRJ_wKvYsYOqb23FsYKDVQg@mail.gmail.com> 2014-07-01 16:38 ` [Caml-list] Fwd: Toplevel and syntax extension 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 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox