From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id B52FDBCAC for ; Sat, 14 May 2005 00:10:54 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j4DMAsVe019326 for ; Sat, 14 May 2005 00:10:54 +0200 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 AAA18038 for ; Sat, 14 May 2005 00:10:53 +0200 (MET DST) Received: from out1.smtp.messagingengine.com (out1.smtp.messagingengine.com [66.111.4.25]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j4DMAqXw020955 for ; Sat, 14 May 2005 00:10:53 +0200 Received: from frontend3.messagingengine.com (frontend3.internal [10.202.2.152]) by frontend1.messagingengine.com (Postfix) with ESMTP id A1EE5C8EF46; Fri, 13 May 2005 18:10:51 -0400 (EDT) X-Sasl-enc: 2rlXIFjDaVT2nzvjRoShk6W4WQp/SafQUSD96ZNb1fCs1wsCWvrWf+fKSEQM 1116022251 Received: from [172.16.112.115] (burnham.ljcrf.edu [192.231.106.2]) by frontend3.messagingengine.com (Postfix) with ESMTP id B1213AE; Fri, 13 May 2005 18:10:50 -0400 (EDT) Date: Fri, 13 May 2005 15:10:49 -0700 (PDT) From: Martin Jambon X-X-Sender: martin@localhost To: Richard Jones Cc: caml-list@inria.fr Subject: Re: [Caml-list] Very strange camlp4 error when using records In-Reply-To: <20050513195425.GA5994@furbychan.cocan.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 428525EE.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 428525ED.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocamlc:01 -pp:01 cmo:01 mlast:01 cmo:01 ocamlc:01 -pp:01 rec:01 iter:01 endline:01 toplevel:01 lowercase:01 char:01 expr:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: On Fri, 13 May 2005, Richard Jones wrote: [...] > $ ocamlc -pp "camlp4o pa_extend.cmo q_MLast.cmo" -I +camlp4 -c pa_test2.ml > $ ocamlc -pp "camlp4o ./pa_test2.cmo" -I +camlp4 -c test2.ml > File "test2.ml", line 1, characters 11-18: > Unbound value t.a > $ camlp4o ./pa_test2.cmo pr_o.cmo test2.ml > type t = { a : int } > let rec t t = Array.iter print_endline [| string_of_int t.a |] > (* generated code above compiles just fine in toplevel or ocamlc *) You have to be careful that the strings that you introduce in the AST as "lid" (lowercase identifier), "uid" (uppercase identifier), "str" (escaped string) or "chr" (escaped char) are *not checked*. What you do indirectly in your AST generator ("generate") is: <:expr< string_of_int $lid: "t.a" >> ^^^ that's not a lid but it is pretty-printed as if it was one Instead of: <:expr< string_of_int $lid:"t"$ . $lid:"a"$ >> (this is also OK: <:expr< string_of_int t.a >> ) This why you get an error message that you would never get in hand-written OCaml (it would be "Unbound value t" or "Unbound record field label a"). Martin > -- pa_test2.ml ----------------------------------------------- > let rec generate loc name = function > | <:ctyp< int >> -> > <:expr< string_of_int $lid:name$ >> > | <:ctyp< { $list:fields$ } >> -> > let fields = List.map ( > fun (loc, fname, mut, tdef) -> > let name = name ^ "." ^ fname in > generate loc name tdef > ) fields in > <:expr< Array.iter print_endline [| $list:fields$ |] >> > | _ -> assert false > > DELETE_RULE > Pcaml.str_item: "type"; LIST1 Pcaml.type_declaration SEP "and" > END > > EXTEND > GLOBAL: Pcaml.str_item; > > Pcaml.str_item: > [[ "type"; tds = LIST1 Pcaml.type_declaration SEP "and" -> > let typedefs = <:str_item< type $list:tds$ >> in > let values = List.map ( > fun ((loc, name), tparams, tdef, cl) -> > let body = generate loc name tdef in > <:patt< $lid:name$ >>, <:expr< fun $lid:name$ -> $body$ >> > ) tds in > <:str_item< > declare > $typedefs$; > value rec $list:values$; > end > >> ]]; > END > -------------------------------------------------------------- > > -- test2.ml -------------------------------------------------- > type t = { a : int } > -------------------------------------------------------------- > > Ideas? > > Rich. > > -- > Richard Jones, CTO Merjis Ltd. > Merjis - web marketing and technology - http://merjis.com > Team Notepad - intranets and extranets for business - http://team-notepad.com > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > -- Martin Jambon, PhD http://martin.jambon.free.fr