如何以静默方式加载顶层模块

时间:2018-04-04 03:57:56

标签: ocaml toplevel ocaml-toplevel

在我的~/.ocamlinit中,我有一些指示:

#use "topfind"
#thread
#require "core.top"

结果,每当OCaml顶层(即ocaml)开始时,我就会得到这么大的文字墙:

        OCaml version 4.02.3

Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

/usr/lib/ocaml/threads: added to search path
/usr/lib/ocaml/unix.cma: loaded
/usr/lib/ocaml/threads/threads.cma: loaded
/usr/lib/ocaml/compiler-libs: added to search path
/usr/lib/ocaml/bigarray.cma: loaded
/home/user/.opam/system/lib/bin_prot: added to search path
/home/user/.opam/system/lib/bin_prot/bin_prot.cma: loaded
/home/user/.opam/system/lib/fieldslib: added to search path
/home/user/.opam/system/lib/fieldslib/fieldslib.cma: loaded
/usr/lib/ocaml/nums.cma: loaded
/home/user/.opam/system/lib/num-top: added to search path
/home/user/.opam/system/lib/num-top/num_top.cma: loaded
/home/user/.opam/system/lib/num: added to search path
/home/user/.opam/system/lib/sexplib: added to search path
/home/user/.opam/system/lib/sexplib/sexplib.cma: loaded
/home/user/.opam/system/lib/ppx_assert: added to search path
/home/user/.opam/system/lib/ppx_assert/ppx_assert_lib.cma: loaded
/home/user/.opam/system/lib/ppx_bench: added to search path
/home/user/.opam/system/lib/ppx_bench/ppx_bench_lib.cma: loaded
/home/user/.opam/system/lib/ppx_expect: added to search path
/home/user/.opam/system/lib/ppx_expect/expect_test_common.cma: loaded
/home/user/.opam/system/lib/ppx_expect/expect_test_config.cma: loaded
/home/user/.opam/system/lib/ppx_inline_test: added to search path
/home/user/.opam/system/lib/ppx_inline_test/inline_test_config.cma: loaded
/home/user/.opam/system/lib/ppx_inline_test/ppx_inline_test_lib.cma: loaded
/home/user/.opam/system/lib/ppx_expect/expect_test_collector.cma: loaded
/home/user/.opam/system/lib/result: added to search path
/home/user/.opam/system/lib/result/result.cma: loaded
/home/user/.opam/system/lib/typerep: added to search path
/home/user/.opam/system/lib/typerep/typerep_lib.cma: loaded
/home/user/.opam/system/lib/variantslib: added to search path
/home/user/.opam/system/lib/variantslib/variantslib.cma: loaded
/home/user/.opam/system/lib/core_kernel: added to search path
/home/user/.opam/system/lib/core_kernel/core_kernel.cma: loaded
/home/user/.opam/system/lib/sexplib/sexplib_unix.cma: loaded
/home/user/.opam/system/lib/core: added to search path
/home/user/.opam/system/lib/core/core.cma: loaded
/home/user/.opam/system/lib/core/core_top.cma: loaded
#

当顶层开始时,有没有办法让模块加载静音?

1 个答案:

答案 0 :(得分:4)

trivelt's comment有最好的答案 - 使用utop! - 但如果您或其他人希望直接使用ocaml,您可以将Sys.interactive设置为false以隐藏大部分状态消息。例如:

噪声:

$ ocaml
        OCaml version 4.06.0

# #use "topfind";;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

- : unit = ()

更安静:

$ ocaml
        OCaml version 4.06.0

# Sys.interactive := false;;
- : unit = ()
# #use "topfind";;
- : unit = ()
- : unit = ()

如果您希望自动完成此工作,可以将Sys.interactive := false;;放在.ocamlinit文件的开头,将Sys.interactive := true;;放在最后。