From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id RAA16300 for caml-redistribution; Wed, 15 Nov 1995 17:00:11 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id QAA15728 for ; Wed, 15 Nov 1995 16:28:34 +0100 Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.7.1/8.6.9) with ESMTP id QAA23063; Wed, 15 Nov 1995 16:28:25 +0100 (MET) Received: (from mauny@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id QAA15714; Wed, 15 Nov 1995 16:28:25 +0100 Message-Id: <199511151528.QAA15714@pauillac.inria.fr> Subject: Re: Why no macros in CAML Light ? To: Pierre.Weis@inria.fr (Pierre Weis) Date: Wed, 15 Nov 1995 16:28:25 +0100 (MET) Cc: tarizzo@world-net.sct.fr, caml-list@margaux.inria.fr In-Reply-To: <199511150936.KAA08832@pauillac.inria.fr> from "Pierre Weis" at Nov 15, 95 10:36:47 am From: Michel.Mauny@inria.fr (Michel Mauny) Reply-to: Michel.Mauny@inria.fr Organization: INRIA, BP 105, F-78153 Le Chesnay Cedex, France Phone: (+33) 1 39 63 57 96 -- Fax: (+33) 1 39 63 53 30 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis > > I wonder why there is no macro facility in CAML. > > > it would be nice to have at least the equivalent of C macros. > > No problem with this feature: you just have to write an equivalent of the C > preprocessor (for instance in Caml itself) and make it available to > the community! Even simpler: use the C preprocessor itself! (with the -P option) I know, it is tractable only under Unix, and using Makefiles... > > Perhaps, there are implementation problems related with the type system of > > CAML, but I can't figure out what they could be. > Finally, the problem of macros in Caml is still an active research > area ``in the background'', since it is definitively very powerful and > elegant (and completely safe in conjonction with the type system): I > hope it will be incoporated into Caml someday. In these lines, Daniel > de Rauglaudre and Michel Mauny have designed and implemented a > prototype of a new Caml dialect (we call it Chamau) with a very > powerful ``quotation'' facility, which provides a powerful macro > facility, which is still reasonably compatible with separate compilation. I would simply say `compatible', not `reasonably compatible'. By the way, quotations are some concrete way of noting structures such as abstract syntax trees. For example, writing <> instead of the binary tree: Node("p", Leaf "x", Node("q", Leaf "z", Leaf "t")). Quotations are just implicit calls to (user-defined) parsers. They provide some (controlled) syntax extension facility. Back to the discussion, now. Just to make it clear, macros and quotations aren't exactly the same thing. Neither macros, nor quotations cause real separate compilation problems. (Well, for macros, it depends on the design.) Both of them are compile-time evaluation (a function call for quotations -- the function being known by the compiler --, and arbitrary evaluations for macros). Both of them simply need some good properties from the compiler. On the other hand, macros, if implemented with an `eval' function, need some form of dynamic typechecking. (To make sure that a macro-evaluation -- that is, an arbitrary expression being evaluated at compile-time -- returns a piece of program, expression or pattern or..., according to the occurrence of the macro call in the source.) For implementing syntax extensions, macros are just the most powerful tool. That may be too much. Quotations are more restrictive, and more reasonable as a syntax extension tool (in the sense that one can make sure, in the design of the quotation mechanism, that there won't be no dynamic type-checking). The ultimate solution for syntax extensions, to my opinion, is to have an extensible syntax. The only problem for that, is that the Yacc technique isn't powerful enough. About quotations, interested people may have a look at: @InProceedings{Mauny-de-Rauglaudre94a, author = "Michel Mauny and Daniel de Rauglaudre", title = "A complete and realistic implementation of quotations for {ML}", booktitle = "Record of the 1994 {ACM-SIGPLAN} Workshop on {ML} and its Applications", page = "70--78", month = jun, year = 1994 } -- Michel