Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Configuring emacs to work with caml

20 views
Skip to first unread message

C. Fr

unread,
Jan 16, 2010, 5:33:09 PM1/16/10
to caml...@yquem.inria.fr
Hello everyone�!

I�ve recently started coding in Caml, and I like it very much. I�m running
both Linux (Ubuntu) and windows, and on both systems I use emacs. However,
I�ve come into a few difficulties when configuring emacs under windows. More
specifically, I�ve been trying to create a portable setup of
camllight/ocaml, so as to run it from a USB stick.

My first step was to extract the contents of an Windows Caml package, to get
the binaries -- I couldn�t find anything but an installer, so I basically
copied the folders bin and lib to my USB. The files are organized in a tree
that looks like this :

--(USB Root)
-----(emacs files and folders)
-----\caml-bin
--------\camllight
-----------\bin
-----------\lib
--------\ocaml
-----------\bin
-----------\lib

Then, I installed the Caml mode for emacs by following that can be found
here : http://www.cs.jhu.edu/~scott/pl/caml/emacs.html

Of course, to make sure that my .emacs file could be found, I created the
following "site-start.el":

-- site-lisp\site-start.el --
(defvar program-dir (substring data-directory 0 -4))

(defvar caml-bin (concat program-dir "caml-bin"))
(defvar ocaml-bin (concat program-dir "caml-bin/ocaml/bin"))
(defvar ocaml-lib (concat program-dir "caml-bin/ocaml/lib"))
(defvar camllight-bin (concat program-dir "caml-bin/camllight/bin"))
(defvar camllight-lib (concat program-dir "caml-bin/camllight/lib"))

(setenv "HOME" program-dir)
(setenv "OCAMLLIB" ocaml-lib)
(setenv "CAMLLIB" camllight-lib)
(setenv "PATH" (concat (concat caml-bin ";") (getenv "PATH")))
(setenv "PATH" (concat (concat ocaml-bin ";") (getenv "PATH")))
(setenv "PATH" (concat (concat camllight-bin ";") (getenv "PATH")))
-- end of site-lisp\site-start.el --

Plus, I added to my .emacs file the following lines:

-- .emacs (USB drive root) --
(setq auto-mode-alist (cons '("\\.ml[iylp]?" . caml-mode) auto-mode-alist))
(autoload 'caml-mode "caml" "Major mode for editing Caml code." t)
(autoload 'run-caml "inf-caml" "Run an inferior Caml process." t)
(autoload 'camldebug "camldebug" "Run the Caml debugger." t)
-- end of .emacs --

Now, when I launch emacs, and use the built-in shell (M-!) to type ocaml or
caml, I get the regular caml prompt (adding CAMLLIB and OCAMLLIB solved a
few bugs), perfectly functional.
However, when I launch run-caml, and then type either "ocaml" or "caml" when
asked which toplevel to run ("Caml Toplevel to run:"), I invariably get the
message "Searching for program: no such file or directory, ocaml". However,
when I put the "ocaml.exe" file directly in emacs bin directory, the problem
vanishes.

Has someone ever encountered a similar problem? I just can't manage to find
a solution, and would like to preserve my directory tree...
Thanks a lot for your support !


_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Alexander Voinov

unread,
Jan 16, 2010, 6:22:04 PM1/16/10
to caml...@yquem.inria.fr
Hi All,

This is a syntax extension I've been using since 2003:

http://www.voinov.org/FP/spbSyntax.tgz

It defines a number of constructs, which make List traversals look like
loops over arrays/sequences in popular languages like Python:

map [1;2;3] with e -> e + 1

filtermap [1;2;3] with e when e mod 2 == 0 -> Some e | _ -> None

foldl [1;2;3] from 0 with s0, e -> s0 + e

iterate [1;2;3] with e -> printf "%d\n" e done

and some more like this.

It relies upon camlp5 instead of (new) camlp4. It maps those constructs into
the corresponding functions of ExtLib (not the standard List module), so
that one can use tail recursion optimization.

The motivation to this syntax extension was as follows. I've been working in
bioinformatics and we have had ~10000000 lines of Python code in our CVS.
I've started to use OCaml for some applications where I needed more runtime
speed than Python could deliver and still didn't want to dive into C++. Also
I tried to promote OCaml among my Pythonic colleagues. That is why I enjoyed
a possibility to make list processing constructs looking like Python loops
over lists (that is, dynamic arrays). I've identified a number of common use
cases and mapped each of them onto an appropriate higher order function from
the Extlib library. On the caml side, these extensions look similar to the
match ... with construct.

An example code, included into the distribution show how I've been and still
am using these extensions in practical applications.

Thank you!

Alexander

C. Fr

unread,
Jan 17, 2010, 3:06:19 AM1/17/10
to caml...@yquem.inria.fr
Hello again!

I have found a solution to my portable emacs problem. The trick is to use
the program-dir variable defined in site-start.el to pass it to the run-caml
code, so that it can deal with absolute paths.

Thanks for Caml!

blue storm

unread,
Jan 17, 2010, 3:24:22 AM1/17/10
to Alexander Voinov, caml...@yquem.inria.fr
Thanks for the release : it's interesting to see syntax extensions in use.
I have a few question/remarks.

1) Are you interested in a camlp4 (>= 3.10) port ?

2) The use of the Extlib module is hardcoded in the syntax extension.
I would find it nicer if you only referred to "List.map" instead of
"Extlib.List.map", and let the user "open Extlib" if he wants to
override the stdlib. That would allow one to use other implementations
of List.
You could also add an option to use "List.map" instead of
"Extlib.List.map", if you want Extlib to be the default.

3) iterate/iteratei use a closing "done" lexeme. I understand that it
was nicer for use in a ;-sequence, but doesn't it somehow break the
homogeneity with the "match .. with" construct ?

4) It could be interesting to parametrize the syntax extension of the
precise collection module used. In my own pa_comprehension [1]
extension, i use "Module : expression" (in you setting that would be
something like "map Array : e with ...") for that purpose. You could
instead choose to make the used module implicit (expand to "map"
instead of "List.map" or "Extlib.List.map"), and let an external
openin-like facility do the job. As I understand an open_in syntax is
going to be included in the mainstream for 3.12, that's probably the
best solution.

[1] http://git.ocamlcore.org/cgi-bin/gitweb.cgi?p=batteries/batteries.git;a=blob;f=src/syntax/pa_comprehension/README;h=e17aa35b72a54d7db28c5f8b8dcb19ed40df1b68;hb=HEAD

Newsgroups Fr

unread,
Jan 19, 2010, 1:12:24 PM1/19/10
to
On Jan 16, 11:33 pm, "C. Fr" <newsgroups...@gmail.com> wrote:
> Hello everyone !
>
> I’ve recently started coding in Caml, and I like it very much. I’m running
> both Linux (Ubuntu) and windows, and on both systems I use emacs. However,
> I’ve come into a few difficulties when configuring emacs under windows. More
> specifically, I’ve been trying to create a portable setup of
> camllight/ocaml, so as to run it from a USB stick.
>

Hello!
I'm posting a link to a website explaining the whole configuration
process for quick reference if some searches for the same thing as I
did, ie. a way to configure a portable caml light or ocaml + emacs
environment on windows.

Damien Doligez

unread,
Jan 25, 2010, 12:42:47 PM1/25/10
to blue storm, caml...@yquem.inria.fr

On 2010-01-17, at 09:24, blue storm wrote:

> 2) The use of the Extlib module is hardcoded in the syntax extension.
> I would find it nicer if you only referred to "List.map" instead of
> "Extlib.List.map", and let the user "open Extlib" if he wants to
> override the stdlib. That would allow one to use other implementations
> of List.


You can do this if you want to use the stdlib instead of extlib:

module Extlib = struct module List = List end;;

Rather ugly, but it should work...

-- Damien

Alexander Voinov

unread,
Jan 25, 2010, 4:46:20 PM1/25/10
to Damien Doligez, blue storm, caml...@yquem.inria.fr
Hi All,

I've updated this extension to remove the dependency on ExtLib (as suggested
previously). The price is that iteratei is not available with the core List
module.

If you do need iteratei, first uncomment the

# WITH_ITERATEI = 1

line in the Makefile (and do a fresh build), and, second, always

open ExtLib;;

The tarball is: http://www.voinov.org/FP/spbSyntax-1.0.1.tgz

(and also http://www.voinov.org/FP/spbSyntax.tgz)

Regarding camlp4, I don't remember why this extension didn't work with it
after that big refactoring, which gave birth to camlp5. I'm making a TODO
for myself to take a look at this.

Thank you!

Alexander

Alexander Voinov

unread,
Jan 25, 2010, 7:14:38 PM1/25/10
to blue storm, caml...@yquem.inria.fr, Damien Doligez
Hi

I've thrown in your version and used it within that big app, a portion of
which I've presented as an 'example' for the syntax extension. Everything
works well. I've also checked that the compiler correctly points to
locations of syntax errors (probably this was the problem which forced me to
move to camlp5). I will test it more.

Can I incorporate your contribution into the deliverable for that extension?

Now that this tiny project grows, it's probably worth introducing a
configure script with parameters like --without-interatei and
--enable-camlp5.

Thank you!

Alexander

From: blue storm [mailto:bluesto...@gmail.com]
Sent: Monday, January 25, 2010 2:32 PM
To: Alexander Voinov
Cc: Damien Doligez; caml...@yquem.inria.fr
Subject: Re: [Caml-list] A syntax extension to simplify List manipulation

On Mon, Jan 25, 2010 at 10:45 PM, Alexander Voinov <avo...@gmail.com>
wrote:

I've updated this extension to remove the dependency on ExtLib (as suggested
previously). The price is that iteratei is not available with the core List
module.

If you do need iteratei, first uncomment the

# WITH_ITERATEI = 1

line in the Makefile (and do a fresh build), and, second, always

open ExtLib;;


I think you should keep iteratei by default : if the user use an
insufficient List module, he will get a classical "unbound value
List.iteratei" error from the compiler, and will easily relate it to the
code using your extension (as the "iteratei" name is apparent).
If you document that point, it could be much easier than a compile-time
option that requires one to edit the Makefile. If you really want an option
to disallow iteratei syntaxically, you could use command-line options to
make that choice at runtime (that would be more flexible).
I don't know how well camlp5 handle command-line parameters, so I can't help
you there.

Regarding camlp4, I don't remember why this extension didn't work with it
after that big refactoring, which gave birth to camlp5. I'm making a TODO
for myself to take a look at this.


In case you're interested, attached is a short camlp4 (>= 3.10) port of your
extension (wich wasn't thoroughly tested). As you can see, changes are
minimal. This is just in case, I don't have any opinion on what preprocessor
you should use.

(and also http://www.voinov.org/FP/spbSyntax.tgz)

PS : the software license is the zlib/png license. Maybe you should mention
it explicitely.

blue storm

unread,
Jan 25, 2010, 7:39:10 PM1/25/10
to Alexander Voinov, caml...@yquem.inria.fr, Damien Doligez
On Tue, Jan 26, 2010 at 1:14 AM, Alexander Voinov <avo...@gmail.com> wrote:

> Can I incorporate your contribution into the deliverable for that
> extension?
>

Do with my code as your please.

0 new messages