首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在emacs、ubuntu上包含camlp4

如何在emacs、ubuntu上包含camlp4
EN

Stack Overflow用户
提问于 2015-02-28 18:22:13
回答 2查看 107关注 0票数 0

我有下面的源代码。你能帮助我为我的emacs配置camlp4,这样我就可以运行这段代码了吗?非常感谢

代码语言:javascript
复制
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 ]
EN

回答 2

Stack Overflow用户

发布于 2015-02-28 23:35:35

您正在使用列表理解,这是Camlp4的一部分。要在终端仿真器中编译此代码,应键入

代码语言:javascript
复制
ocamlfind c -package camlp4.listcomprehension -syntax camlp4o -c a.ml

编译行与emacs或camlmode无关。但是,如果您想在toplevel中尝试此代码,则需要键入以下内容:

代码语言:javascript
复制
$ 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";;

要将camlp4安装到您的机器上,您需要为Ubuntu或opam预编译包。

票数 3
EN

Stack Overflow用户

发布于 2015-03-02 10:14:55

谢谢你,卡卡度。我想我找到我的答案了。首先,我在我的ubuntu上安装了camlp4。

代码语言:javascript
复制
apt-get install camlp4
apt-get install camlp4-extra

然后,我在源代码中创建了一个文件.ocamlinit并添加:

代码语言:javascript
复制
#load "dynlink.cma";;
#load "camlp4of.cma";;

我认为这些步骤已经解决了我上面的问题,

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28780624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档