ocamlcamlp4ocamlfindutop

replace camlp4 with camlp5 in utop


I'm working with OCaml code that needs camlp5; however, the toplevel (I'm using utop) automatically loads the newer, incompatible camlp4. These are the startup messages:

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

The .ocamlinit im using looks like this:

#use "topfind";;
#thread;;

I installed camlp5 with opam and it shows up when I issue ocamlfind list; also the file camlp5.cma is located in /home/<username>/.opam/4.02.1/lib/camlp5/camlp5.cma. But trying to load camlp5o and camlp5r fails with Unknown directive camlp5o.

How can i make utop aware of camlp5 and how can I replace camlp4 with camlp5 as the default preprocessor?

Many thanks in advance!


Solution

  • $ ocaml
        OCaml version 4.02.1
    
    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
    
    # #require "camlp5";;
    /home/kakadu/.opam/4.02.1/lib/camlp5: added to search path
    # #load "camlp5o.cma";;
        Camlp5 parsing version 6.12
    
    #