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 UAA31670; Wed, 6 Aug 2003 20:14:43 +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 UAA31004 for ; Wed, 6 Aug 2003 20:14:41 +0200 (MET DST) Received: from mwinf0601.wanadoo.fr (smtp3.wanadoo.fr [193.252.22.25]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h76IEff23196 for ; Wed, 6 Aug 2003 20:14:41 +0200 (MET DST) Received: from warp (ABordeaux-103-1-26-151.w193-252.abo.wanadoo.fr [193.252.175.151]) by mwinf0601.wanadoo.fr (SMTP Server) with SMTP id 5CE2A340011A; Wed, 6 Aug 2003 20:14:40 +0200 (CEST) Message-ID: <005b01c35c46$a466ea20$2b00a8c0@warp> From: "Nicolas Cannasse" To: , "Richard Jones" Cc: "David Brown" , "Vovka" , References: <20030806151051.GB29704@redhat.com> <20030806174330.GA30804@redhat.com> Subject: Re: [Caml-list] static class member.... Date: Wed, 6 Aug 2003 20:14:47 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; cannasse:01 warplayer:01 caml-list:01 bug:01 foo:01 accessors:01 incr:01 printf:01 compiler:01 ocaml:01 nicolas:01 objects:02 variable:03 object:03 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > Yes, it says in the language introduction (the part on objects) > > > > Let-bindings within class definitions are evaluated before the object > > is constructed > > Well I take it back. And I must admit that I always have used > let-bindings as if they are local to the instance. > > The question though is why does my example work? Is this a bug > in the compiler? It's not a bug. You can see your class as function to get a better idea of what's happenning : let foo = let x = ref 0 in (fun () -> !x) against : let foo () = let x = ref 0 in !x To answer to the original post about class static, there is no concept of static class variables in Ocaml , but you can still write accessors to a variable declared outside the class scope : let counter = ref 0 class foo = object method incr = incr counter method print = Printf.printf "counter = %d\n" !counter end Nicolas Cannasse ------------------- 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