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.1 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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 121A7BC69 for ; Fri, 23 Mar 2007 17:35:24 +0100 (CET) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.227]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2NGZMAh002695 for ; Fri, 23 Mar 2007 17:35:23 +0100 Received: by wx-out-0506.google.com with SMTP id i31so1482939wxd for ; Fri, 23 Mar 2007 09:35:22 -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=oSmL7kWGH5/zeJGur6R4lpNizV5GAb3SEL4JU05K2IvS3gps0/CrNZvRKmgMUEGWrTOyfoblOYHUwnggwkhdGE1l/nGF7FkCbrpw3qA7gwDyYn1o32VjbYNY8bO5/EQcXpYvSio8pks5XbYKxJHW/AFpGSZsAIhzMa7xP2VODNE= 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=j1xPvW3Io0G+ZpIvImnrLNFMlhV2+l5FSzbx2TkokrS+WFvZJEJd26cFeg+Fj4Dn3qHil7R+4731H1XoLDxlI//F54yXMruQE7w5W/gVUsJxxGb5SjzEDkQvc73OWYh8U90zi51BOQbHTytTto32Ii+TyJN3m6XOklEjm4zicLY= Received: by 10.114.169.2 with SMTP id r2mr1262205wae.1174667721275; Fri, 23 Mar 2007 09:35:21 -0700 (PDT) Received: by 10.114.183.4 with HTTP; Fri, 23 Mar 2007 09:35:21 -0700 (PDT) Message-ID: Date: Fri, 23 Mar 2007 17:35:21 +0100 From: "Nicolas Pouillard" To: "Martin Jambon" Subject: Re: [Caml-list] Camlp4 3.10.0+beta: lists without $list:...$ Cc: caml-list@inria.fr In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-j-chkmail-Score: MSGID : 460401CA.001 on concorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at concorde with ID 460401CA.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 ens-lyon:01 camlp:01 ctyp:01 ctyp:01 semicolons:01 syntax:01 bindings:01 bindings:01 mutable:01 expr:01 expr:01 lexbuf:01 lexbuf:01 inlined:01 On 3/23/07, Martin Jambon wrote: > I managed to create an object type using camlp4orf: > > let ctyp_object _loc ml = > let fields = > List.fold_left > (fun o (name, typ) -> > let m = <:ctyp< $lid:name$ : $typ$ >> in > <:ctyp< $o$; $m$ >>) > <:ctyp< >> ml in > <:ctyp< < $fields$ > >> > > where ml is a list of method declarations of type (string * ctyp) list. > Before we just had to do this: > > <:ctyp< < $list:ml$ > >> > > Is there anything simpler than my solution? Is a shortcut available? In fact there is some shortcuts but it was not for all constructions (fixed now in CVS). There is functions underlining these shortcuts like Ast.tySem_of_list that join a list with semicolons. I can explain briefly the change... Before there was lists inside the tree. In order to allow a fully reflective mechanism we now avoid these from the AST. So there is now many more concrete syntax for any part of the AST (match branches, let bindings, record field bindings...). (p, None, e) -> <:match_case< $p$ -> $e$ >> (p, Some guard, e) -> <:match_case< $p$ when $guard$ -> $e$ >> (loc, field, true, typ) -> <:ctyp< { $lid:field$ : mutable $typ$ } >> ... If m1 and m2 are to match branches (like (p, None, e) for the old one): <:match_case< $m1$ | $m2$ >> You want some default cases: <:match_case< A -> 1 | $m1$ | B x -> x | $m2$ | _ -> assert False >> So, when one wrote something like: let cases = List.mapi (fun i (_,e) -> <:patt< $int:string_of_int i$ >>, None, e) brs in let cases = cases @ [<:patt< _ >>, None, <:expr< raise Ulexing.Error >>] in let actions = <:expr< match __ulex_state_0 lexbuf with [ $list:cases$ ] >> in We now can write: let cases = List.mapi (fun i (_,e) -> <:match_case< $`int:i$ -> $e$ >>) brs in <:expr< match __ulex_state_0 lexbuf with [ $list:cases$ | _ -> raise Ulexing.Error ] } >> Where the error case is inlined in the match directly. This <:patt< $int:string_of_int i$ >>, None, e is a typical thing where no syntax were available to it. Now you can write <:match_case< $`int:i$ -> $e$ >> since any part of the abstract syntax have a quotation in concrete syntax. You can note that in `` [ $list:cases$ '' I used the $list:...$ antiquotation that was used to inject some list in a tree. In 3.10 you can still do that, but that's a sugar for a function call that will join all your trees by the proper separator (bar here). FYI, I've just added all the missing $list:$ sugars to the CVS version (will be public soon). > PS: any progress on the manual? It's kind of hard to test new features > when you don't know what they are. I agree, but there is still no progress on the documentation :( BTW, have you read these slides http://gallium.inria.fr/~pouillar/pub/camlp4/renovation-camlp4-longue.pdf -- Nicolas Pouillard