简体   繁体   English

如何在Emacs,Ubuntu上包含camlp4

[英]How to include camlp4 on emacs, ubuntu

I have source code below. 我下面有源代码。 I knew it doesn't work becaus missing camlp4. 我知道这是行不通的,因为缺少camlp4。 Now my OS is Ubuntu, I am using caml mode for emacs editor. 现在我的操作系统是Ubuntu,我正在将caml模式用于emacs编辑器。 Can you please help me to config camlp4 for my emacs, so I can run this code ? 您能帮我为我的emacs配置camlp4,以便我运行此代码吗? 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. 您正在使用的列表理解是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. 编译行与emacs或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 . 要将camlp4安装到您的计算机上,您需要预编译的Ubuntu软件包或opam软件包。

Thank you, Kakadu so much. 非常感谢卡卡杜。 I think I figure out my answer. 我想我想出了答案。 Firstly, I install camlp4 on my ubuntu. 首先,我在ubuntu上安装camlp4。

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

Then, I create a file .ocamlinit in my source code and add: 然后,在我的源代码中创建一个文件.ocamlinit并添加:

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

I think these steps is solved my problem above, 我认为这些步骤已经解决了我上面的问题,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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