caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Configuring emacs to work with caml
@ 2010-01-16 22:33 C. Fr
  2010-01-16 23:21 ` A syntax extension to simplify List manipulation Alexander Voinov
  0 siblings, 1 reply; 8+ messages in thread
From: C. Fr @ 2010-01-16 22:33 UTC (permalink / raw)
  To: caml-list

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 ! 



^ permalink raw reply	[flat|nested] 8+ messages in thread

* A syntax extension to simplify List manipulation
  2010-01-16 22:33 Configuring emacs to work with caml C. Fr
@ 2010-01-16 23:21 ` Alexander Voinov
  2010-01-17  8:24   ` [Caml-list] " blue storm
  0 siblings, 1 reply; 8+ messages in thread
From: Alexander Voinov @ 2010-01-16 23:21 UTC (permalink / raw)
  To: caml-list

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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] A syntax extension to simplify List manipulation
  2010-01-16 23:21 ` A syntax extension to simplify List manipulation Alexander Voinov
@ 2010-01-17  8:24   ` blue storm
  2010-01-25 17:42     ` Damien Doligez
  0 siblings, 1 reply; 8+ messages in thread
From: blue storm @ 2010-01-17  8:24 UTC (permalink / raw)
  To: Alexander Voinov; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] A syntax extension to simplify List manipulation
  2010-01-17  8:24   ` [Caml-list] " blue storm
@ 2010-01-25 17:42     ` Damien Doligez
  2010-01-25 21:45       ` Alexander Voinov
  0 siblings, 1 reply; 8+ messages in thread
From: Damien Doligez @ 2010-01-25 17:42 UTC (permalink / raw)
  To: blue storm; +Cc: Alexander Voinov, caml-list


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [Caml-list] A syntax extension to simplify List manipulation
  2010-01-25 17:42     ` Damien Doligez
@ 2010-01-25 21:45       ` Alexander Voinov
  2010-01-25 22:32         ` blue storm
  0 siblings, 1 reply; 8+ messages in thread
From: Alexander Voinov @ 2010-01-25 21:45 UTC (permalink / raw)
  To: 'Damien Doligez', 'blue storm'; +Cc: caml-list

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

-----Original Message-----
From: Damien Doligez [mailto:damien.doligez@inria.fr] 
Sent: Monday, January 25, 2010 9:43 AM
To: blue storm
Cc: Alexander Voinov; caml-list@yquem.inria.fr
Subject: Re: [Caml-list] A syntax extension to simplify List manipulation


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] A syntax extension to simplify List manipulation
  2010-01-25 21:45       ` Alexander Voinov
@ 2010-01-25 22:32         ` blue storm
  2010-01-26  0:14           ` Alexander Voinov
  0 siblings, 1 reply; 8+ messages in thread
From: blue storm @ 2010-01-25 22:32 UTC (permalink / raw)
  To: Alexander Voinov; +Cc: Damien Doligez, caml-list


[-- Attachment #1.1: Type: text/plain, Size: 1693 bytes --]

On Mon, Jan 25, 2010 at 10:45 PM, Alexander Voinov <avoinov@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.

[-- Attachment #1.2: Type: text/html, Size: 2551 bytes --]

[-- Attachment #2: spbSyntax_camlp4.ml --]
[-- Type: application/octet-stream, Size: 2533 bytes --]

(* This is a camlp4 port (from camlp5) of Alexander Voinov's "simplify
   List manipulation" syntax extension. Source changes were minimal.

   See below for the original copyright notice.

   Compilation command used :
     ocamlfind ocamlc -syntax camlp4o -package camlp4.extend,camlp4.quotations -c spbSyntax_camlp4.ml
*)

(*
 * Copyright (c) 2003-2010 Alexander Voinov

 * This software is provided 'as-is', without any express or implied
 * warranty. In no event will the authors be held liable for any damages
 * arising from the use of this software.

 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:

 * 1. The origin of this software must not be misrepresented; you must
 * not claim that you wrote the original software. If you use this
 * software in a product, an acknowledgment in the product documentation
 * would be appreciated but is not required.

 * 2. Altered source versions must be plainly marked as such, and must
 * not be misrepresented as being the original software.

 * 3. This notice may not be removed or altered from any source
 * distribution.
 * (The text of this license is borrowed from one found in ocamlnet-2.2.9)
 *)

open Camlp4
open PreCast
open Syntax

EXTEND Gram
  GLOBAL: expr;

  expr: 
    LEVEL "top" [ [ "map"; list = expr; "with"; OPT "|"; clauses = LIST1 match_case SEP "|" ->
	  <:expr< List.map (fun [ $list:clauses$ ]) $list$ >> ]

    | [ "filtermap"; list = expr; "with"; OPT "|"; clauses = LIST1 match_case SEP "|" ->
	  <:expr< List.filter_map (fun [ $list:clauses$ ]) $list$ >> ]

    | [ "iterate"; list = expr; "with"; OPT "|"; clauses = LIST1 match_case SEP "|"; "done" ->
	  <:expr< List.iter (fun [ $list:clauses$ ]) $list$ >> ]
	
    | [ "iteratei"; list = expr; "with"; OPT "|"; clauses = LIST1 match_case SEP "|"; "done" ->
	  <:expr< List.iteri (fun n h -> match (n, h) with [ $list:clauses$ ]) $list$ >> ]

    | [ "foldr"; list = expr; "from"; initval = expr; "with"; OPT "|"; 
	clauses = LIST1 match_case SEP "|" ->
	  <:expr< List.fold_right (fun a b -> 
				     match (a, b) with [ $list:clauses$ ]) 
	                           $list$ $initval$ >> ]

    | [ "foldl"; list = expr; "from"; initval = expr; "with"; OPT "|"; 
	clauses = LIST1 match_case SEP "|" ->
	  <:expr< List.fold_left (fun a b -> 
				     match (a, b) with [ $list:clauses$ ]) 
	                           $initval$ $list$ >> ]
    ];
END


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [Caml-list] A syntax extension to simplify List manipulation
  2010-01-25 22:32         ` blue storm
@ 2010-01-26  0:14           ` Alexander Voinov
  2010-01-26  0:39             ` blue storm
  0 siblings, 1 reply; 8+ messages in thread
From: Alexander Voinov @ 2010-01-26  0:14 UTC (permalink / raw)
  To: 'blue storm'; +Cc: 'Damien Doligez', caml-list

[-- Attachment #1: Type: text/plain, Size: 2508 bytes --]

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:bluestorm.dylc@gmail.com] 
Sent: Monday, January 25, 2010 2:32 PM
To: Alexander Voinov
Cc: Damien Doligez; caml-list@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 <avoinov@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.


[-- Attachment #2: Type: text/html, Size: 7172 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] A syntax extension to simplify List manipulation
  2010-01-26  0:14           ` Alexander Voinov
@ 2010-01-26  0:39             ` blue storm
  0 siblings, 0 replies; 8+ messages in thread
From: blue storm @ 2010-01-26  0:39 UTC (permalink / raw)
  To: Alexander Voinov; +Cc: Damien Doligez, caml-list

[-- Attachment #1: Type: text/plain, Size: 194 bytes --]

On Tue, Jan 26, 2010 at 1:14 AM, Alexander Voinov <avoinov@gmail.com> wrote:

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

Do with my code as your please.

[-- Attachment #2: Type: text/html, Size: 662 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-01-26  0:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-16 22:33 Configuring emacs to work with caml C. Fr
2010-01-16 23:21 ` A syntax extension to simplify List manipulation Alexander Voinov
2010-01-17  8:24   ` [Caml-list] " blue storm
2010-01-25 17:42     ` Damien Doligez
2010-01-25 21:45       ` Alexander Voinov
2010-01-25 22:32         ` blue storm
2010-01-26  0:14           ` Alexander Voinov
2010-01-26  0:39             ` blue storm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).