From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.2 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id D5DF9BC69 for ; Mon, 19 Mar 2007 16:37:21 +0100 (CET) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.234]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2JFbJxD026256 for ; Mon, 19 Mar 2007 16:37:20 +0100 Received: by wr-out-0506.google.com with SMTP id 60so1536281wri for ; Mon, 19 Mar 2007 08:37:19 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=sQyybJfUqi+nHBmxCEHMlFzmp5BdiGau6yDZuB1aBpLjbG47l7Kc4LLfEJCRMD6GCmdenZrS+HYchOC6g4FblVMOvPqRN6e+6XZXTTZ6h8YkAyOejPJhmzIh5Aun01XinbSxbZVhywOP+ytcIanWUEYv7+fRXQg6v07bfAoYusI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=CxQAv4rs7NYID7iYOqBLQHQ7O0BQwrvqllTxroMF+EVRYJOINihbsqiMRZK5ERmuoX91wy2m5OCPL455RxTeVmr3taLAWLhjIwjZi8wYOcudtS/FYx4fN94DPoHdZEACKuIewO779IluaQ1gPm0sHFSqkSFeZpDG8iXT7CCCnQ8= Received: by 10.100.152.9 with SMTP id z9mr3832099and.1174318638675; Mon, 19 Mar 2007 08:37:18 -0700 (PDT) Received: by 10.114.183.4 with HTTP; Mon, 19 Mar 2007 08:37:18 -0700 (PDT) Message-ID: Date: Mon, 19 Mar 2007 16:37:18 +0100 From: "Nicolas Pouillard" To: "Loup Vaillant" Subject: Re: [Caml-list] Where are the AST specs? Cc: "Caml List" In-Reply-To: <6f9f8f4a0703190742w3cd42978ib23a78163542729f@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <6f9f8f4a0703181022q2b9d7f8bt33919e07f3799c65@mail.gmail.com> <95513600703190145h5a0c6202t518ff61fcde83655@mail.gmail.com> <6f9f8f4a0703190217o5a975a78s16fe2be77825af01@mail.gmail.com> <6f9f8f4a0703190353p4d38ea32k30e1ad2a00f70f4@mail.gmail.com> <6f9f8f4a0703190742w3cd42978ib23a78163542729f@mail.gmail.com> X-j-chkmail-Score: MSGID : 45FEAE2F.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 45FEAE2F.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 camlp:01 expr:01 expr:01 cmo:01 wrote:01 wrote:01 rec:01 rec:01 caml-list:01 assert:01 assert:01 writes:01 macros:01 macros:01 On 3/19/07, Loup Vaillant wrote: > 2007/3/19, Nicolas Pouillard : > > On 3/19/07, Loup Vaillant wrote: > > > another example: > > > (+ x y z) > > > > > > (plus (plus x y) z) > > > > Yes the macro extension is to weak for that. > > Here is a camlp4 snippet todo it: > > [...] > > Looks promising. Now, I have more: > (* x y z) > (:: x y z []) > etc. You see the pattern? I need a "fold" macro that writes those macros. open Camlp4.PreCast;; AstFilters.register_str_item_filter begin Ast.map_expr begin function | <:expr@loc< foldl($lid:op$, $e$) >> -> let rec foldl = function | [] -> assert false | [x] -> x | x :: xs -> <:expr@loc< $lid:op$ $foldl xs$ $x$ >> in foldl (List.rev (Ast.list_of_expr e [])) | <:expr@loc< foldr($lid:op$, $e$) >> -> let rec foldr = function | [] -> assert false | [x] -> x | x :: xs -> <:expr@loc< $lid:op$ $x$ $foldr xs$ >> in foldr (Ast.list_of_expr e []) | e -> e end end#str_item;; $ cat test_macros.ml let cons x xs = x :: xs;; foldl(( + ), 1, 2, 3, 4);; foldr(cons, 1, 2, 3, []);; $ camlp4o ./macros.cmo test_macros.ml let cons x xs = x :: xs let _ = ((1 + 2) + 3) + 4 let _ = cons 1 (cons 2 (cons 3 [])) > Besides, I think my biggest challenge will probably be the automatic > handling of "loc", and a beautiful anti quotation system. You're right loc is something hard. What's wrong with the current anti quotation system? -- Nicolas Pouillard