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 23B92BC69 for ; Thu, 31 May 2007 17:29:16 +0200 (CEST) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.179]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4VFTE8I021923 for ; Thu, 31 May 2007 17:29:15 +0200 Received: by wa-out-1112.google.com with SMTP id n7so288257wag for ; Thu, 31 May 2007 08:29:14 -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=WvSNVki2ceuAdAbpC3ObanpsekP1b8Ec7Lirdbxjr/g624fBnDo8JxbGRAr+P7DuulKtKOlF/Pdzt6t13BCPzNB9wHz7JNmoy1pDXq5rn/0MhSSpt9aEO9v9EHKDHuF1o5iKLFWHksiPt3XnvevMU13B9p9TI27e3BGzQAd7ox4= 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=Q2opsZPmZDRDi7exdP24q8sCDwIQO1Y6d5pkUwTxe0hd83vSijpQmQjThzhOn2PjvInSWu2jMR9G5mStg2IVPizk8HXuOmtUHE0cMXTL8zOhmj1JDIByg3pz8QWKFP5Nfn3lNZKeWGv3f13+mOI3mwXEQ8DvagYmEMdYOa+Z43U= Received: by 10.115.58.1 with SMTP id l1mr710426wak.1180625354555; Thu, 31 May 2007 08:29:14 -0700 (PDT) Received: by 10.114.181.8 with HTTP; Thu, 31 May 2007 08:29:14 -0700 (PDT) Message-ID: Date: Thu, 31 May 2007 17:29:14 +0200 From: "Nicolas Pouillard" To: "Joel Reymont" Subject: Re: GenerateFold Cc: "OCaml List" In-Reply-To: <5F8F1647-A4A8-4C71-9958-9370C44ECB84@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <5F8F1647-A4A8-4C71-9958-9370C44ECB84@gmail.com> X-j-chkmail-Score: MSGID : 465EE9CA.002 on concorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at concorde with ID 465EE9CA.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; decl:01 decl:01 expr:01 camlp:01 camlp:01 val:01 wrote:01 exception:01 inherit:01 inherit:01 ast:02 ast:02 tree:02 match:02 match:02 On 5/31/07, Joel Reymont wrote: > What is the proper use of GenerateFold here? > > What I'm trying to do is dig into my AST tree, starting with a list > of statements at the top, to find out if I have any `FunArgDecl bits. > > At the top of the AST I have > > statement = > [ > | `InputDecls of input_decl list > ] > > and then > > input_decl = > [ > | `InputDecl of id * ty * expr > | `FunArgDecl of id * ty * subscript > ] > > I tried the following approach but it's obviously wrong. > > class fold = Camlp4Filters.GenerateFold.generated;; > > let is_fun_arg = object > inherit fold as super > method input_decl x = > match super#input_decl x with > | `FunArgDecl _ -> true > | _ -> false > end > > let is_fun x = is_fun_arg#statement x;; > You must use the object itself that is threaded through the traversal (or use an exception in that simple case). Something like (not tested). class fold = Camlp4Filters.GenerateFold.generated;; let is_fun_arg = object inherit fold as super val found = false method found = found method input_decl x = match super#input_decl x with | `FunArgDecl _ -> {< found = true >} | _ -> self end let is_fun x = (is_fun_arg#statement x)#found;; -- Nicolas Pouillard