|Anonymous | Login | Signup for a new account||2018-12-15 07:53 CET|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0007551||OCaml||documentation||public||2017-06-04 13:50||2017-07-11 21:44|
|Target Version||Fixed in Version|
|Summary||0007551: caml_example pseudo-environment in the language extension chapter|
|Description||Following a recent change in the manual build, it is now possible to use the "caml_example" pseudo-environment in the language extension chapter of the manual.|
Compared to the standard verbatim environment, this pseudo-environment has the advantage to check that the written code is valid, protecting it from bitrot; it also offers the possibility of showing the result of the evaluation of toplevel phrase.
Therefore, it might be a good idea to go through the language extension chapter and replace "verbatim" environment with eitheir "caml_example" or "caml_example*" environment whenever appropriate. The "caml_example" environment should be used whenever the result of the written code is illustrative, whereas the "caml_example*" one discards this results. Another useful environment would be the "caml_eval" environment which can be used to setup the right variables and definition for the "caml_example"'s without displaying anything.
Note that sometimes the verbatim environment is used to introduce "ocaml pseudo-code", in these cases, keeping the verbatim environment is probably better.
So I just tried to start working on it, but I realize that caml_example always expects to get well-formed ocaml phrases, and in particular it expects ;; at the end of sequences. For example one verbatim use in the document is
module F(X : sig type c = private < x : int; .. > end) =
let get_x (o : X.c) = o#x
module G(X : sig type c = private < x : int; y : int; .. > end) =
let get_y (o : X.c) = o#y
Turning it into caml_example* without any other change gets me the following error:
Error when evaluating a caml_example environment in exten.etex:
missing ";;" at line 349
On the other hand, I don't really want to litter the code with ";;", because I think it's good that some part of the manual would show OCaml code as we write it (and not only toplevel-style code).
While `ocaml` breaks on the code above without a closing double-semicolon, `ocaml -stdin` correctly accepts it (it parses the two phrases, etc.). Would it be possible for the caml_example environment to also correctly behave in this situation? Maybe we could just stealthily add a ";;" at the end? (It looks like the toplevel does not complain on ";; ;;", which suggests that it would work fine for toplevel-style examples as well.)
|It should be totally possible to tune caml_tex2 to close toplevel phrase at the end of the environment when the current phrase is non-empty. I remember hesitating between this behavior and the current strict behavior when I implemented the current error message. It should be also quite straightforward to add a [toplevel] option to the environment to enable the strict behavior on missing ";;". I am not sure if it is worthwhile however.|
|I would be happy with whatever you are willing to implement :-)|
|Ok, I have an implementation proposal here: https://github.com/ocaml/ocaml/pull/1194 [^] .|
The behavior that we merged uses a new (non-optional) argument, "toplevel" or "verbatim":
for toplevel input (with an expected ;; at the end), and
when ";;" delimiters are not expected. Either can be combined with the [error] marker to indicate that we expect the test to fail:
1 + "foo"
|2017-06-04 13:50||octachron||New Issue|
|2017-06-04 13:50||octachron||Tag Attached: junior_job|
|2017-06-04 13:50||octachron||Tag Attached: manual|
|2017-06-07 02:51||gasche||Note Added: 0017845|
|2017-06-07 03:07||octachron||Note Added: 0017846|
|2017-06-07 03:31||gasche||Note Added: 0017847|
|2017-06-07 16:46||octachron||Note Added: 0017849|
|2017-06-07 21:01||gasche||Note Added: 0017850|
|2017-07-11 21:44||octachron||Status||new => confirmed|
|Copyright © 2000 - 2011 MantisBT Group|