From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA29828; Thu, 24 Oct 2002 14:51:42 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA02657 for ; Thu, 24 Oct 2002 14:51:41 +0200 (MET DST) Received: from verdot.inria.fr (verdot.inria.fr [128.93.11.7]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9OCpf506184 for ; Thu, 24 Oct 2002 14:51:41 +0200 (MET DST) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id OAA13728 for caml-list@inria.fr; Thu, 24 Oct 2002 14:51:40 +0200 Date: Thu, 24 Oct 2002 14:51:40 +0200 From: Daniel de Rauglaudre To: caml-list@inria.fr Subject: Re: [Caml-list] Again on pattern matching and strings Message-ID: <20021024145140.J12351@verdot.inria.fr> References: <3DB73515.90705@baretta.com> <15799.14325.887770.501722@karryall.dnsalias.org> <3DB7A4B9.1030607@baretta.com> <20021024105136.C12351@verdot.inria.fr> <3DB7E8B8.80200@baretta.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <3DB7E8B8.80200@baretta.com>; from alex@baretta.com on Thu, Oct 24, 2002 at 02:34:00PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, On Thu, Oct 24, 2002 at 02:34:00PM +0200, Alessandro Baretta wrote: > > Does "evaluated at parse time" mean that you define a syntax > tree transformation as opposed to a character stream > transformation? Right. The general idea of Camlp4, anyway, is manipulation of syntax tree. Every syntax extension work with syntax trees, not character stream. The extension DEFMACRO or DEFINE, which I propose to add in Camlp4, uses correct syntax trees. The syntax of this construction uses the normal lexing and parsing of OCaml expressions. The substitutions of possible parameters will be scans of the syntax trees and tree substitution. (Virtual) Example: DEFMACRO f(x) (x, x) f(3+y) function f(2) -> 0 would be interpreted as: (3+y, 3+y) function (2, 2) -> 0 We may be interested in "inlining" with this system: but in this case, if we accept any expression, it would not work in pattern position. Example: DEFMACRO f(x) (x+3) f(2) would be interpreted as: 2+3 but function f(2) -> 0 has no meaning. > This is more or less what I had in mind. The only problem > with this scheme is probably with compile-time error > reporting. If this is not somehow linked with the compiler, > how will the compiler be able to tell us that that something > we wrote makes no sense? Indeed if the macro is a complicated expression, the typing error might be difficult to understand. As location, I can only underline all the macro call: DEFMACRO f(x) (x, "hello") function (x, y) -> (x + 2, y + 5) | f(3) -> (22, 35) ^^^^ This pattern has type string and is used with type int. Something like that... -- Daniel de RAUGLAUDRE http://cristal.inria.fr/~ddr/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners