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 DAA19089; Sat, 14 Jul 2001 03:14:36 +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 DAA04036 for ; Sat, 14 Jul 2001 03:14:35 +0200 (MET DST) Received: from localhost.localdomain (cartman103.zip.com.au [61.8.20.231]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f6E1EVT03165 for ; Sat, 14 Jul 2001 03:14:32 +0200 (MET DST) Received: from maxtal.com.au (IDENT:root@localhost [127.0.0.1]) by localhost.localdomain (8.9.3/8.8.7) with ESMTP id LAA15943; Thu, 12 Jul 2001 11:49:01 +1000 Message-ID: <3B4D020D.4039A62F@maxtal.com.au> Date: Thu, 12 Jul 2001 11:49:01 +1000 From: John Max Skaller X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: en MIME-Version: 1.0 To: boost@yahoogroups.com, caml-list@inria.fr Subject: [Caml-list] RFC: get/set vs get/ref References: <0107111558020P.12210@baxter> <00a701c10a15$9b1db190$6701a8c0@abeast1.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk [posted to caml-list@inria.fr and boost@yahoogroups.com] I seek your opinion on get/set vs. get/ref. Suppose we desire to abstract an immutable data type. We can do that by providing 'get' methods to access the data. The canonical examples are a) tuples: represented by projection functions b) lists: represented by 'head' and 'tail' functions When the data type is mutable, there are two choices. The simplest choice is to provide set methods. For example, for a mutable string, with C++ notation: char string::get_char (int pos) const void string::set_char (int pos, char ch) For Algol like languages, we could also provide references: char string::get_char (int pos)const char &string::ref_char (int pos) The difference is exemplified by the following techniques for incrementing a character: s.set ((s.get(pos) + 1),pos) // get/set method s.ref(pos).++ // ref method Clearly, ref methods are more powerful and more efficient, but on the other hand they expose the underlying implementation and prevent hooking changes to the mutable state. What's the best technique? -- John (Max) Skaller, mailto:skaller@maxtal.com.au 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 New generation programming language Felix http://felix.sourceforge.net Literate Programming tool Interscript http://Interscript.sourceforge.net ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr