ocaml top:获取用户的输入

时间:2014-02-23 11:37:06

标签: ocaml typerex

您能否告诉我如何在Ocaml-top中获取用户的输入?

可在此链接中找到:http://www.typerex.org/ocaml-top.html

我是Ocaml的初学者,我正在尝试让用户的输入运行this example

这是代码:

let rec hilo n =
     let () = print_string "type a number: " in
     let i = read_int () 
     in 
       if i = n then 
         let () = print_string "BRAVO" in
         let () = print_newline ()
         in print_newline ()
       else 
         let () = 
           if i < n then 
             let () = print_string "Higher"
             in print_newline () 
           else 
             let () = print_string "Lower"
             in print_newline ()
         in hilo n ;;

但程序停在Type a number

3 个答案:

答案 0 :(得分:1)

这实际上是不可能的。 OCaml-top通过标准输入将其命令发送到ocaml解释器,read_int也读取stdin上的输入。在https://github.com/OCamlPro/ocaml-top/issues/45

跟踪此问题

答案 1 :(得分:0)

尝试从命令提示符运行它。 在命令提示符下键入以下命令:ocaml filename.ml 只有在环境变量中设置路径时才能使用它。

答案 2 :(得分:0)

我有这个工作,上面文件的差异为零

$ ocaml

启动解释器

# #directory "/home/wherever-your-OCaml-stuff-is";;

是的,输入额外的 # 和 ;;

# #use "hilo.ml";;

不需要编译任何东西

# hilo 24356256456;;

这不是一个猜谜游戏......