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,e859f774bbb3dfb3 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: another way to shoot yourself in the foot? Date: Tue, 24 Jun 2008 16:31:31 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <54157920-377a-441b-9b0b-f0c4f9ddffec@f36g2000hsa.googlegroups.com> <54435596-5e7f-4686-a2b7-1e22d7c4b186@p25g2000hsf.googlegroups.com> <483ugmvkl2ea.1hrqsq7ru4t1x$.dlg@40tude.net> <12dhu8e1w5ac9.1s9hzkf9d2rsy$.dlg@40tude.net> <21d80cc3-a3fb-49f5-a46e-6056bbef2ba7@y21g2000hsf.googlegroups.com> <1lbujyle8itjn$.vffs9far1ob9.dlg@40tude.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1214339492 11923 192.74.137.71 (24 Jun 2008 20:31:32 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 24 Jun 2008 20:31:32 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:gA8r+0vhnVbaMma89WUU4X40UQ0= Xref: g2news1.google.com comp.lang.ada:849 Date: 2008-06-24T16:31:31-04:00 List-Id: "Jeffrey R. Carter" writes: > Robert A Duff wrote: >> Well, I don't think so, but anyway, this is the only way >> return of limited types can make sense. The Ada 83 way >> (return is by copy, even for limited) is just wrong. >> And the Ada 95 way (return by reference) is confusing >> and nearly useless. > > I don't know about "nearly useless". The only thing you could do with a > limited function result in Ada 95 (and Ada 83) was pass it to a > subprogram or entry. Not quite the "only" -- you could rename it. > ...There are times when that is useful. But in Ada 95, if you say: P(F(...)); where F returns limited, you are not passing a limited object, but an implicit reference to some object that already existed before the call to F. You can do that more clearly by having F return an access type. I really think return-by-ref was a mistake. Too bad we didn't think of it in 1992. For that matter, too bad JDI didn't think of it in 1980. ;-) > The new way seems to be biased towards build in place for object > initialization. Well, there are only two ways a function call can be used: to initialize a new object, or to update an existing object (i.e. on the right-hand side of an assignment statement). But don't forget there are a dozen or so different ways of creating new objects (components, parameters, parent parts of aggregates, etc). All of these are allowed for build-in-place function calls. The only thing that's not allowed is the assignment statement. You can still say: P(F(...)); where F returns a limited type. Yes, there's a new object being created (the formal parameter of P), and F is being used to initialize that object (in place!). In Ada 2005, functions always return newly-created objects, which I think is appropriate. A couple more examples: X : Array_Of_Lim := (1..10 => F(...)); if F(...).Flag then ... The last one is pretty silly -- it creates a new limited object, grabs a boolean flag out of it, and then throws the whole thing away. - Bob