Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Sequencing toplevel phrases in `ocaml` #8813
It seems that
Is there any rationale about this or does it qualify as a bug ?
More specifically I find the following discrepancy suprising:
> echo 'print_endline "bla";; print_endline "bli";;' > /tmp/bla.ml > ocaml -noinit OCaml version 4.08.0 # #use "/tmp/bla.ml";; bla - : unit = () bli - : unit = () # print_endline "bla";; print_endline "bli";; bla - : unit = () #
Also it seems syntax errors are allowed after the first
# print_endline "bla";; lat x = 3;; bla - : unit = ()
Indeed, the toplevel resets the input buffer after each phrase ending in ;; is read from the user, which results in the behaviour you have observed:
You can stop blindly resetting the input buffer after each phrase is read, but that results in strange interactions like:
To improve on this it would be necessary to read several phrases at once and evaluate them all at once. The problem is knowing when to stop waiting for input. Basically, you need to stop reading after seeing ;; if this would cause the lexer to block waiting for input. As far as I know this is not easily done with the current
I'm not sure that I follow: EOF is typically only sent to finish the session, right?