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
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
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!
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.
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.
> 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
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
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.
The tarball is: http://www.voinov.org/FP/spbSyntax-1.0.1.tgz
(and also http://www.voinov.org/FP/spbSyntax.tgz)
PS : the software license is the zlib/png license. Maybe you should mention
it explicitely.
> Can I incorporate your contribution into the deliverable for that
> extension?
>
Do with my code as your please.