caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: blue storm <bluestorm.dylc@gmail.com>
To: Alexander Voinov <avoinov@gmail.com>
Cc: Damien Doligez <damien.doligez@inria.fr>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] A syntax extension to simplify List manipulation
Date: Mon, 25 Jan 2010 23:32:11 +0100	[thread overview]
Message-ID: <527cf6bc1001251432n1e72c0b6idd26154e32cccfb9@mail.gmail.com> (raw)
In-Reply-To: <005b01ca9e07$c254d6a0$46fe83e0$@com>


[-- 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


  reply	other threads:[~2010-01-25 22:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2010-01-26  0:14           ` Alexander Voinov
2010-01-26  0:39             ` blue storm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=527cf6bc1001251432n1e72c0b6idd26154e32cccfb9@mail.gmail.com \
    --to=bluestorm.dylc@gmail.com \
    --cc=avoinov@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=damien.doligez@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).