From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a3736685ef876ab2 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!out04b.usenetserver.com!news.usenetserver.com!in04.usenetserver.com!news.usenetserver.com!news-in-02.newsfeed.easynews.com!easynews.com!easynews!sn-xt-sjc-02!sn-xt-sjc-10!sn-xt-sjc-01!sn-post-sjc-02!sn-post-sjc-01!supernews.com!corp.supernews.com!not-for-mail From: Matthew Heaney Newsgroups: comp.lang.ada Subject: Re: OO Style with Ada Containers Date: Mon, 26 Nov 2007 04:21:55 +0000 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <1195082906.420079.195000@d55g2000hsg.googlegroups.com> <1195084214.480299.13970@t8g2000prg.googlegroups.com> <1195084752.840598.174460@v65g2000hsc.googlegroups.com> <1195086265.070953.93180@d55g2000hsg.googlegroups.com> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (windows-nt) Cancel-Lock: sha1:OjdtiejJLdGRjDRfxdHwsgViGzs= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@supernews.com Xref: g2news1.google.com comp.lang.ada:18620 Date: 2007-11-26T04:21:55+00:00 List-Id: braver writes: > I'm still pondering the workings of the Next (S.H.S.all) above. Why > three (!) dots-dereferences? Because the mode for parameter S of function Word is in-mode, but the mode for parameter of procedure Next is inout-mode. The Rosen Trick is a clean way (subject to certain constraints) to "cast away const". (Try calling operation Next with parameter S directly -- what does the compiler say?) Here's how the Rosen Trick works: S is a "constant view" of the scanner object. S.H refers to the "handle" of the scanner object. S.H.S.all refers to the discriminant of the handle, and the discriminant here refers to the "current instance" of the same scanner object, but with a "variable view" (that's why type Handle was declared with "access Scanner" as the discriminant instead of "access constant Scanner"). An operation with a "variable view" of an object can modify the state of the object. So Word cannot directly modify its parameter S, since its parameter has only a "constant view". But S.H.S.all is a "variable view", so the parameter can be modified indirectly (though the handle part of the object). I know that's weird, but that's just the way it is (C++ is much more sensible here, since a class can have non-const member functions). As Robert Dewar puts it, functions in Ada are allowed to modify their parameters -- they're just not allowed to say they do!