Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About the "topfind"?

Tags:

ocaml

When I input #use "topfind" ;; in top-level manually, it works as below:

 #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 #use "topfind" ;;
  - : unit = ()

However, when I put #use "topfind";; in ~/.ocamlinit file, it doesn't work:

>cat ~/.ocamlinit
#use "topfind";;
#require "str";; 
(* #use "money.ml" ;; *)

>ocaml
    Objective Caml version 3.12.0
# #list ;;
Unknown directive `list'.

It seems a strange question, isn't it?

like image 859
z_axis Avatar asked Feb 22 '23 11:02

z_axis


2 Answers

Obviously ocaml doesn't load that .ocamlinit. Put some print_endline in it to verify. Some ideas:

  • You can use -init option to specify ocamlinit file explicitely.
  • Maybe ocaml is some (wrong) alias in your shell?
  • Try strace -f -ttT -e open $(which ocaml) to see where it looks for ocamlinit.
like image 69
ygrek Avatar answered Feb 25 '23 02:02

ygrek


ygrek

thanks for your quick answer.

You can use -init option to specify ocamlinit file explicitely.

%ocaml -init ~/.ocamlinit works

Maybe ocaml is some (wrong) alias in your shell?

no ocaml alias

Try strace -f -ttT -e open $(which ocaml) to see where it looks for ocamlinit

%strace -f -ttT -e open $(which ocaml) 
19:12:28.484440 open("/etc/ld.so.cache", O_RDONLY) = 3 <0.000179>
19:12:28.485002 open("/lib/libm.so.6", O_RDONLY) = 3 <0.000062>
19:12:28.485384 open("/lib/libdl.so.2", O_RDONLY) = 3 <0.000062>
19:12:28.485744 open("/lib/libncursesw.so.5", O_RDONLY) = 3 <0.000061>
19:12:28.486107 open("/lib/libpthread.so.0", O_RDONLY) = 3 <0.000061>
19:12:28.486514 open("/lib/libc.so.6", O_RDONLY) = 3 <0.000060>
19:12:28.488228 open("/usr/bin/ocamlrun", O_RDONLY|O_LARGEFILE) = 3 <0.000018>
19:12:28.488425 open("/usr/bin/ocaml", O_RDONLY|O_LARGEFILE) = 3 <0.000166>
19:12:28.496499 open("/usr/lib/ocaml/ld.conf", O_RDONLY|O_LARGEFILE) = 4 <0.000028>
19:12:28.502249 open("/usr/bin/ocaml", O_RDONLY|O_LARGEFILE) = 3 <0.000021>
19:12:28.506085 open("/usr/lib/ocaml/ld.conf", O_RDONLY|O_LARGEFILE) = 4 <0.000029>
19:12:28.506880 open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3 <0.000020>
Objective Caml version 3.12.1
19:12:28.507797 open("/usr/lib/ocaml/pervasives.cmi", O_RDONLY|O_LARGEFILE) = 3 <0.000019>
19:12:28.511012 open(".ocamlinit", O_RDONLY|O_LARGEFILE) = 3 <0.000018>
19:12:28.511325 open("money.ml", O_RDONLY|O_LARGEFILE) = 4 <0.000020>
19:12:28.513412 open("/usr/lib/ocaml/list.cmi", O_RDONLY|O_LARGEFILE) = 5 <0.000018>
19:12:28.514858 open("/usr/lib/ocaml/printf.cmi", O_RDONLY|O_LARGEFILE) = 5 <0.000020>
19:12:28.527847 open("/usr/lib/ocaml/sys.cmi", O_RDONLY|O_LARGEFILE) = 5 <0.000029>
#

The reason is that there is a .ocamlinit file in the current directory. so ocaml uses it instead of ~/.ocamlinit.

thanks!

like image 21
z_axis Avatar answered Feb 25 '23 02:02

z_axis