gpt4 book ai didi

ubuntu - 如何在 emacs、ubuntu 上包含camlp4

转载 作者:行者123 更新时间:2023-12-04 18:57:59 25 4
gpt4 key购买 nike

我有下面的源代码。我知道它不起作用,因为缺少camlp4。现在我的操作系统是 Ubuntu,我在 emacs 编辑器中使用 caml 模式。你能帮我为我的emacs配置camlp4,这样我就可以运行这段代码了吗?
太感谢了

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 ]

最佳答案

您正在使用作为 Camlp4 一部分的列表理解。要在终端模拟器中编译此代码,您应该键入

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

编译行与 emacs 或 camlmode 无关。但是,如果您想在顶层尝试此代码,则需要输入:

$ 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 预编译的软件包。 .

关于ubuntu - 如何在 emacs、ubuntu 上包含camlp4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28780624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com