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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.182.121.232 with SMTP id ln8mr17085783obb.11.1400518924487; Mon, 19 May 2014 10:02:04 -0700 (PDT) X-Received: by 10.50.137.67 with SMTP id qg3mr110198igb.2.1400518924401; Mon, 19 May 2014 10:02:04 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!hl10no1363451igb.0!news-out.google.com!qf4ni2017igc.0!nntp.google.com!c1no10649705igq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 19 May 2014 10:02:03 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <79ced891-4a1a-4008-ade8-875228e5dc03@googlegroups.com> Subject: Re: A question about syntax or semantics From: Adam Beneschan Injection-Date: Mon, 19 May 2014 17:02:04 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:19902 Date: 2014-05-19T10:02:03-07:00 List-Id: On Saturday, May 17, 2014 3:56:20 PM UTC-7, Victor Porton wrote: > From Ada2012 Reference Manual: >=20 > arm2012.html/rm-4-1-3.html > [[[ > A selected_component that is not an expanded name shall resolve to denote= =20 > one of the following: >=20 > A view of a subprogram whose first formal parameter is of a tagged ty= pe=20 > or is an access parameter whose designated type is tagged: > ]]] >=20 > Why it is significant to have it only for the first formal parameter? >=20 > Please explain with examples. Well, this thread took some pretty bizarre turns, for reasons I don't under= stand.=20 This looks more like a "why did the language designers do it this way" ques= tion than an exam question to me, so I'll try to answer (note: I'm not one = of the language designers). Ada 95 introduced object-oriented concepts into the language by using tagge= d types. However, unlike other OO languages, in which an "instance method"= is thought of as primarily applying to a certain object, which is then tre= ated specially in the syntax of a method call (contrasted with any other ob= jects that might be passed as parameters), Ada 95 treated the "instance" as= a parameter just like all the other parameters. (There can be more than o= ne parameter of the same tagged type; if dispatching, i.e. polymorphism, ta= kes place, the language requires that all such parameters have the same typ= e. So there's no question about which parameter is "preferred" when decidi= ng which subprogram is actually called.) However, this led to problems. From AI95-252: "This one was prompted in part by the reactions of Erhard's grad students to the difficulty of having to both identify the package containing an operation and the object on which the operation is to be performed. With both classwide and primitive operations being relevant, and these operations having essentially opposite rules about which package the operation resides in (the ultimate ancestor for classwide, and the ultimate descendant for primitive), some way to eliminate the package from the syntax seemed useful. "The other prompting factor is the continual whining that Ada 95 is out of the mainstream of OOP languages because it lacks the object.operation syntax. This proposal defines the 'object.op' syntax as essentially a syntactic sugar on the pkg.op(object,...) syntax. This approach is pretty much what Modula-3 did. It provides for a 'symmetric' notation when dealing with binary operators, while also providing an 'asymmetric' (object-oriented) syntax when using operations that have a single controlling operand." (http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-00252.txt?rev= =3D1.16) So when they added this feature to Ada 2005, Ada already had subprograms th= at would take an object of the tagged type as a parameter (and would dispat= ch if necessary), and their intent was to provide a new syntax on top of th= e existing feature to allow for an Object.Operation(...) notation, rather t= han add a whole new "instance method" concept, which would have been unnece= ssary. So given that Object.Operation was going to be a new syntax to refe= r to an existing type of subprogram call, I think tying the "Object" to the= first parameter of an existing subprogram was the only reasonable solution= . First, as Brad pointed out, you have to deal with operations with more t= han one parameter of the type: procedure Operation (X1, X2 : Some_Tagged_Type); You can't really allow both X1.Operation(X2) and X2.Operation(X1) as two di= fferent ways to specify a call to Operation(X1, X2). That would be ambiguo= us.=20 Another possibility would be to let the declaration of Operation specify wh= ich of its parameters should be used as the parameter of interest in an Obj= ect.Operation call. But I think that would have made things really complex= . Finally, they could have decided that the *first* *tagged* parameter of any= operation would be the one used for Object.Operation notation, so that procedure Operation (P1 : Integer; P2 : Some_Tagged_Type; P3 : Integer)= ; could be called like X : Some_Tagged_Type; X.Operation(100, 200); which would be equivalent to=20 Operation(100, X, 200); But I think that would have caused a lot of extra work both for language de= signers and for compiler implementors, for very little gain. I suspect tha= t most Ada 95 programs were already putting the tagged object of interest f= irst in their parameter lists anyway (that's just a guess, though; I don't = really have any evidence). Anyway, I hope that answers the question of why it's important to have the = feature for the first parameter only. -- Adam >=20 >=20 >=20 >=20 >=20 > --=20 >=20 > Victor Porton - http://portonvictor.org