Re: [Caml-list] [OSR] Standard syntax extensions ?

2008-05-01 Thread Richard Jones

For the record, here's a better version by bluestorm:

  http://bluestorm.info/camlp4/pa_matches.ml.html

Rich.

-- 
Richard Jones
Red Hat

___
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


Re: [Caml-list] [OSR] Standard syntax extensions ?

2008-04-27 Thread David Teller
I think this would be useful. However, you can already do it in a
slightly more complex fashion.

From the top of my mind, with

let ( /* ) f g = f g
let ( */ ) f g x = g f x

you can achieve

1 /* mem */ [1;2;3]

with the added bonus that a C programmer will never be able to read your
code :)

Cheers,
 David

On Sat, 2008-04-26 at 09:53 +0200, Till Crueger wrote:
 I am posting this in this thread, because this would allow us to write the  
 above more elegantly as:
 1 `mem` [1;2;3], which is close to what was originally proposed.
 
 What do you think of this?
 
 bye,
Till
 
 
-- 
David Teller
 Security of Distributed Systems
  http://www.univ-orleans.fr/lifo/Members/David.Teller
 Angry researcher: French Universities need reforms, but the LRU act brings 
liquidations. 

___
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


Re: [Caml-list] [OSR] Standard syntax extensions ?

2008-04-26 Thread Richard Jones
On Fri, Apr 25, 2008 at 01:37:47PM -0700, Arthur Chan wrote:
 Would it be difficult to have python-like syntax for List.exists?  Could we
 add it to Hashtbl and Array too?  I'm not too fond of python's general
 sloppiness, but the (x in mylist) syntax seemed very pretty to me.  At the
 least, it correspondes directly to mathematical syntax (x \in blah, for
 Latex ppl).
 
 Does this already exist in a syntax extension?

I'm guessing that there will be ambiguity because you're wanting to
add yet another meaning to the reserved word 'in'.

However I'm not sure why you don't just use 'List.mem', or even:

  let mem = List.mem ;;

  mem 1 [1;2;3]

Did I miss something about how the Python syntax works?

Rich.

-- 
Richard Jones
Red Hat

___
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


Re: [Caml-list] [OSR] Standard syntax extensions ?

2008-04-25 Thread Richard Jones
On Thu, Apr 24, 2008 at 04:52:50PM +0100, John Whitington wrote:
 On 24 Apr 2008, at 16:49, David Teller wrote:
 * what kind of syntactic sugar is absolutely missing from the  
 language ?
 
 I'd like a keyword matches, so I can write
 
 map (matches (0, _, _)) l
 
 rather than
 
 map (function (0, _, _) - true | _ - false) l
 
 Had anyone done that or similar in camlp4?

That's a good idea.  Attached is a trivial camlp4 implementation which
works to a first approximation.  ('when'-clauses don't seem to work
but no doubt would be very simple to fix/add).

Rich.

-- pa_matches.ml
(* matches keyword.
 * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * $Id$
 *
 * Compile with:
 *   ocamlfind ocamlc -I +camlp4 camlp4lib.cma \
 * -pp camlp4of.opt -c pa_matches.ml -o pa_matches.cmo
 * Test with:
 *   ocamlfind ocamlc -pp camlp4o pa_matches.cmo test.ml -o test
 *)

open Camlp4.PreCast
open Syntax
open Ast

let output_matches _loc patt =
  :expr function $patt$ - true | _ - false 

EXTEND Gram
  GLOBAL: expr;

  expr: LEVEL ; [
[ matches; p = patt -
output_matches _loc p
]
  ];

END


-- test.ml
open Printf

let () =
  let xs =
List.filter (matches 7)
  [ 1; 2; 3; 4; 5; 6; 7; 7; 7; 8; 9; 10 ] in
  printf result = %s\n (String.concat ; (List.map string_of_int xs))


--

-- 
Richard Jones
Red Hat

___
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


Re: [Caml-list] [OSR] Standard syntax extensions ?

2008-04-25 Thread Richard Jones
On Thu, Apr 24, 2008 at 10:53:36PM +0200, Berke Durak wrote:
 We absolutely need a standard serialization solution.
 
 I'm thinking of Sexplib of course but it could be another one.  The reason
 it must be standard is that it's difficult to provide
 serialization/deserialization functions outside the imlementation.

It isn't though.  There are several serialization modules (sexplib,
deriving, ...), all of them are packaged up so using them is a simple
'apt-get' away.

 So Sexplib should be a standard extension, or better, it should be included
 in the compiler and used for the .cmo/.cmi/.cmxa files.

Why?

Rich.

-- 
Richard Jones
Red Hat

___
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


Re: [Caml-list] [OSR] Standard syntax extensions ?

2008-04-25 Thread David Teller
The current plans are to have two sets of extensions inside Batteries
Included:
* a few will be opened by default
* some others will just be part of the distribution, with instructions
in a common format, regarding how to activate  use them

In either case, we will probably have a slightly customized ocamlbuild
which doesn't need special plug-ins for these extensions (that's part of
Edgar's side of the work).

Cheers,
 David

On Fri, 2008-04-25 at 09:57 -0400, Peng Zang wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 On Thursday 24 April 2008 01:05:44 pm Dario Teixeira wrote:
  Remember the recent thread about ocamlbuild+findlib+camlp4 and the OSR
  about standardising naming conventions for syntax extensions [1].  Using
  a special ocamlbuild plugin [2], the barrier to using syntax extensions
  is so low that you can almost consider them as standard language features.
 

-- 
David Teller
 Security of Distributed Systems
  http://www.univ-orleans.fr/lifo/Members/David.Teller
 Angry researcher: French Universities need reforms, but the LRU act brings 
liquidations. 

___
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


Re: [Caml-list] [OSR] Standard syntax extensions ?

2008-04-25 Thread Richard Jones
On Fri, Apr 25, 2008 at 06:59:50PM +0200, Berke Durak wrote:
 That would allow people to easily write tools that examine object
 files without relying on the unnecessarily britlle binary format.
 At the very least you could open it in a text editor and see if
 everything's OK inside, or simply grep it.  Yes, there is CMI grep,
 but that one would be even better.  Do this, and you will instantly
 see 10 to 20 new metatools for Ocaml.

But you'll also kill OCaml compiler development.  The *.cm* files
contain representations of the type system, and research on the type
system is the main point of OCaml which is why it changes so much.

Anyway we already have (safe) meta-tools.  We don't need ones which
hack away at internal representations, even if that is a common
development model for Java class files.

Rich.

-- 
Richard Jones
Red Hat

___
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


Re: [Caml-list] [OSR] Standard syntax extensions ?

2008-04-24 Thread Dario Teixeira
Hi,

Thanks for your initiative, David!

 * which syntax extensions do you use so often that you consider they
 should be part of the language ?

Though there are a few so useful (open_in, list comprehensions) they
can almost be considered standard, I still don't think their inclusion
by default is of paramount importance.  The reason?  As long as they
are properly packaged and widely available (namely in the big three:
GODI, Debian, and Fedora), it makes little difference if they are included
by default or not.  After all, they're just a godi_console/apt-get/yum
away.

Remember the recent thread about ocamlbuild+findlib+camlp4 and the OSR
about standardising naming conventions for syntax extensions [1].  Using
a special ocamlbuild plugin [2], the barrier to using syntax extensions
is so low that you can almost consider them as standard language features.

(In theory, anyway.  For the above-described nirvana to become reality,
P4ck needs to be integrated into GODI.  Have you considered it, Martin?).

Cheers,
Dario Teixeira


[1]:
http://www.cocan.org/osr/meta_files_for_packages_containing_syntax_extensions
[2]: http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuild



  __
Sent from Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html

___
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


Re: [Caml-list] [OSR] Standard syntax extensions ?

2008-04-24 Thread Jon Harrop
On Thursday 24 April 2008 17:41:17 Martin Jambon wrote:
 On Thu, 24 Apr 2008, David Teller wrote:
  * which syntax extensions do you use so often that you consider they
  should be part of the language ?

 None because it creates unneeded dependencies between unrelated
 libraries.

Agreed. There are some glaring omissions, like try..finally, but they should 
be fixed properly in the compiler and not using camlpn macros.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e

___
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