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 LAA28086; Wed, 17 Jul 2002 11:26:40 +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 LAA28085 for ; Wed, 17 Jul 2002 11:26:39 +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 g6H9QdX12758 for ; Wed, 17 Jul 2002 11:26:39 +0200 (MET DST) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id LAA12267 for caml-list@inria.fr; Wed, 17 Jul 2002 11:26:39 +0200 Date: Wed, 17 Jul 2002 11:26:38 +0200 From: Daniel de Rauglaudre To: Ocaml Subject: Re: [Caml-list] Recovering masked methods (with CamlP4?) Message-ID: <20020717112638.K7018@verdot.inria.fr> References: <3D335729.3020307@baretta.com> <20020716101520Q.garrigue@kurims.kyoto-u.ac.jp> <3D33E74C.6050307@baretta.com> <20020716095939.M27616@wanadoo.fr> <3D33FE98.6000001@baretta.com> <20020716142655.G29037@verdot.inria.fr> <3D341795.5010301@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: <3D341795.5010301@baretta.com>; from alex@baretta.com on Tue, Jul 16, 2002 at 02:54:45PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, On Tue, Jul 16, 2002 at 02:54:45PM +0200, Alessandro Baretta wrote: > Great! Don't you think this would be a cool addition to the > language? I like it, at least. I cannot judge if it is a good idea or not: I never program with objects and I don't know what is useful or not. I just answer the syntactic point of view. For semantics, please go to the counter "Semantics". ----- For your change: class a = object method m = end into: class var_b = object inherit a as super_a through b as super_b method m = super_a # m end You can do it with this file: ------------------------------------------------ foo.ml #load "pa_extend.cmo";; #load "q_MLast.cmo";; open Pcaml EXTEND GLOBAL: class_str_item; class_str_item: [ [ "method"; l = LIDENT; fb = fun_binding -> let class_a = "__class_a__" ^ l in <:class_str_item< declare method private $lid:class_a$ = $fb$; method m = self # $lid:class_a$; end >> ] ] ; fun_binding: [ RIGHTA [ p = patt LEVEL "simple"; e = SELF -> <:expr< fun $p$ -> $e$ >> | "="; e = expr -> <:expr< $e$ >> | ":"; t = ctyp; "="; e = expr -> <:expr< ($e$ : $t$) >> ] ] ; END ------------------------------------------------ Compile it with: ocamlc -pp camlp4o -I +camlp4 -c foo.ml Then you can compile your example "bar.ml" with the command: ocamlc -pp "camlp4o ./foo.cmo" bar.ml You can also see what the syntax extension does with the command: camlp4o ./foo.cmo pr_o.cmo bar.ml ----- For the case: class var_b = object inherit a as super_a through b as super_b method m = super_a # m end into: class var_b = object inherit b as super_b method m = __class_a__m end It could be done by Camlp4 the same way but there is a small difficulty: it is not really "syntactic sugar" since it supposes, when reaching the item "method m = super_a # m" that you know that "super_a" has been previously defined as "inherit a as super_a through b as super_b". This is mainly "semantics". I mean that the parser should record the information that an "inherit" statement has been defined. It is possible, of course, and I can give you the code which does that, but is it not supposed to be Camlp4 work, if you want to be "pure". The code risks to be a "hack". You have probably to use references to record this information to be possibly used afterwards. -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr 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