-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No standard input/output #162
Comments
Hello there, I'm not sure if it's a known bug to the authors of ocaml-jupyter, but I did encounter it many times. Have you tried to also use It's quite weird, but |
@laowantong yes it appears to be the behavior of jupyter-ocaml. |
No, I honestly never used interactive inputs from any OCaml programs! Sorry |
No problem, thanks again for your kind answer! |
@Naereen Thank you for your answers. https://akabe.github.io/ocaml-jupyter/api/jupyter/Jupyter_comm/Stdin/index.html |
Could it be possible for OCaml-jupyter kernel to patch such functions, like
I actually don't know if OCaml-jupyter kernel has the ability to load a custom
|
I have no idea.
You can specify a custom .ocamlinit file at $ cat $(opam config var share)/jupyter/kernel.json
{
"display_name": "OCaml default",
"language": "OCaml",
"argv": [
"/bin/sh",
"-c",
"eval $(opam config env --switch=default) && /Users/aabe/.opam/default/bin/ocaml-jupyter-kernel \"$@\"",
"ocaml-jupyter-kernel",
"-init", "/Users/aabe/.ocamlinit",
"--merlin", "/Users/aabe/.opam/default/bin/ocamlmerlin",
"--verbosity", "app",
"--connection-file", "{connection_file}"
]
} Re-run |
Awesome! Thank you @akabe for this workaround which works perfectly. I use Jupyter Notebook as an interactive environment in my FP course, and these IO functions are a must for programming games. |
@laowantong, great if that solves the issue for you. But are you really planning to develop a game from Jupyter notebook? Using this Have you had a look at https://github.com/mahsu/MariOCaml ? It's compiled to Javascript using js_of_ocaml (standard tool, it also provided the compiler interpreter at https://betterocaml.ml/editor/ or https://try.ocamlpro.com/. |
@Naereen In fact, I do not call directly this function, but define a mutable variable with a default of: let read = ref read_line; This works under console. Under Jupyter Notebook, I mutate it: read := (function () -> Jupyter_comm.Stdin.read_line "") And for the tests, I use a stream: read := (let x = Stream.of_list ["-10"; "500"; "10"] in function () -> Stream.next x); This is a simple text game (dominoes), nothing as fancy as Mario. Nevertheless, thanks for the links ! |
Interesting! In Python/IPython, it's easy: import IPython
def is_in_notebook(): return IPython.get_ipython() is not None If this is possible in OCaml, it could be used to automatically change your |
You can check whether a repl is on jupyter or not, by: Filename.basename Sys.argv.(0) = "ocaml-jupyter-kernel" This is not perfect, but I think enough in practical cases. module Sys = struct
include Sys
let read () = () [@@ocaml.deprecated "Use Jupyter_comm.Stdin.read_line instead"]
end I don't recommend replace |
Oh great for the hack on For the |
To be able to My I see the kernel.json exports this env by running Is it normal I still need to use the Topdirs.dir_directory function? |
No printing occurs with
print_string
,print_int
, and so on:I would expect an output like under the OCaml REPL:
Is this a known limitation, or am I doing something wrong ? In the first case, is there any workaround?
Thanks!
The text was updated successfully, but these errors were encountered: