简体   繁体   中英

How to include camlp4 on emacs, ubuntu

I have source code below. I knew it doesn't work becaus missing camlp4. Now my OS is Ubuntu, I am using caml mode for emacs editor. Can you please help me to config camlp4 for my emacs, so I can run this code ? Thank you so much

type term = V of string | F of string * term list

let rec symbols = function
  | V x -> [x]
  | F (f, ts) -> f :: [ g | t <- ts; g <- symbols t ]

let rec functions = function
  | V _ -> []
  | F (f, ts) -> f :: [ g | t <- ts; g <- functions t ]

You are using list comprehentions which are the part of Camlp4. To compile this code in terminal emulator you should type

ocamlfind c -package camlp4.listcomprehension -syntax camlp4o -c a.ml

Compilation line is not related to emacs or camlmode. But if you want to try this code in toplevel you need to type this:

$ 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

# #camlp4o;;
/home/kakadu/.opam/4.02.1/lib/ocaml/dynlink.cma: loaded
/home/kakadu/.opam/4.02.1/lib/ocaml/camlp4: added to search path
/home/kakadu/.opam/4.02.1/lib/ocaml/camlp4/camlp4o.cma: loaded
        Camlp4 Parsing version 4.02.1

# #require "camlp4.listcomprehension";;
/home/kakadu/.opam/4.02.1/lib/ocaml/camlp4/Camlp4Parsers/Camlp4ListComprehension.cmo: loaded
# type term = V of string | F of string * term list;;
type term = V of string | F of string * term list
# let rec symbols = function
    | V x -> [x]
    | F (f, ts) -> f :: [ g | t <- ts; g <- symbols t ];;
val symbols : term -> string list = <fun>

$ cat ~/.ocamlinit
#use "topfind";;

To get camlp4 to your machine you need either precompiled packages for Ubuntu or opam .

Thank you, Kakadu so much. I think I figure out my answer. Firstly, I install camlp4 on my ubuntu.

apt-get install camlp4
apt-get install camlp4-extra

Then, I create a file .ocamlinit in my source code and add:

#load "dynlink.cma";;
#load "camlp4of.cma";;

I think these steps is solved my problem above,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM