簡體   English   中英

如何在Emacs,Ubuntu上包含camlp4

[英]How to include camlp4 on emacs, ubuntu

我下面有源代碼。 我知道這是行不通的,因為缺少camlp4。 現在我的操作系統是Ubuntu,我正在將caml模式用於emacs編輯器。 您能幫我為我的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上安裝camlp4。

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

然后,在我的源代碼中創建一個文件.ocamlinit並添加:

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

我認為這些步驟已經解決了我上面的問題,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM