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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c1fe4bc1dd51fc87 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: User-defined type attributes (replacing genericity) Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <30f629fd-69d3-4d40-995f-9933f52b8dad@s37g2000prg.googlegroups.com> <965suhjl0bxt$.74se2ylyksin.dlg@40tude.net> <1205505100.6445.60.camel@K72> <1205513926.7434.3.camel@K72> Date: Fri, 14 Mar 2008 19:39:57 +0100 Message-ID: <84a4svy5kv3b.1o9ncie8w50qi$.dlg@40tude.net> NNTP-Posting-Date: 14 Mar 2008 19:39:57 CET NNTP-Posting-Host: 8d193eec.newsspool4.arcor-online.net X-Trace: DXC=g@_J^=aYicHj7E:bke<5HF4IUK@Tg_N2WK X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:20388 Date: 2008-03-14T19:39:57+01:00 List-Id: On Fri, 14 Mar 2008 17:58:46 +0100, Georg Bauhaus wrote: > On Fri, 2008-03-14 at 15:48 +0100, Dmitry A. Kazakov wrote: > >>> I assume your answer to what follows will be that Ada semantics >>> should be put under programmer control, >> >> What's wrong with having control over the semantics? > > (Control over the semantics of the language. I'm not a compiler, > and I'm not imagining I am as good as someone who can routinely > master the advanced parts of implementing Ada in user programs. > That is what I think will be wrong. But the compiler is in an even worse position. It cannot know your intent when you introduce a new operation, type, object etc. It is up to you to define the semantics of. > It is certainly possible to imagine some meta-flavoring for > Ada. But I don't want to inspect such pieces of sophistication > when they come out of the hands of ordinary programmers > and have errors. There will be at least one more > level of linguistic indirection between me and the LRM: > the programmer's language interpretation as implemented in > his semantics control.) Sorry, but it is generics which constitute a meta language, so this argument you should address to yourself. Further, it seems that you believe that Ada defines some meta-level semantics of attributes and operations like "+", "-", etc. But, it does not. You can define "+" to perform multiplication or to act on tasks. BUT, if you wanted to do that (I don't), then again the first step should be away from generics, towards proper classes. For example, to define a class of additive objects and to forbid use of "+" for anything outside the class. >> No, what you need is an interface implemented by both. You need to declare >> Simple implementing Ordered. That will tell the compiler that the >> predefined "<=" is an implementation of Ordered's "<=". > > Actually, it doesn't matter whether "<=" is predefined. It could > just as well have been a user defined "<=". The Foo(...'Class) would > have had one one general ("generic"?) implementation of Is_Highest, > as described. This Is_Highest will have no specialization, but > it will feature highly stylized indirection, dispatching to the > implementing code for the respective "<=". In fact, your code will not compile. It should be: function Is_Highest (V: T'Class) return Boolean is begin return X <= V and then Y <= V and then Z <= V; end Is_Highest; So what was the problem? >>> Without generics, there is only one Is_Highest, as might be >>> expected. >> >> Why there have to be two? The whole idea of generics was to have *one* >> generic body. This is why it is called generic [programming]. > > I *can* have and I *did* have just one body in *source* code. Yes this is what I meant. > We both know that Ada does not anywhere require that generics > must not yield more than one lists of object code per > generic. This would seem like a stupid restriction, one that > I think no one has wanted to put in the minds of the language > makers. I didn't meant the implementation. Semantically there is one body even if instantiations expand it. >> If you want to constrain the dispatching table to the diagonal > > I don't want that language to inflict a dispatching table > on me when that offers no advantage at all! Dispatching table is not a physical object. It is a formal model to describe operations defined on a class. Such polymorphic operations have type-specific implementations (because the language is strongly typed). The dispatching table lists them according to the order relation (subtyping) of the types of the arguments. How and if to implement it is up to the compiler. > - I don't need any dispatching here, You have to. Dispatch is a selection of a type-specific body responsible for the implementation of a generic (polymorphic) one for the given combination of argument types. When you instantiate a generic body it is an act of dispatching, performed manually. > - My code is more efficient without it, It is not Ada's objective. Then with statically known types and inlined bodies you could have the same code GNAT generics produce. > - Review of the generated code is simpler because > there are fewer indirections. I never review generated code. I wrote large (then) programs about 20K SLOC, now I am using Ada, I don't want back. > - There still is abstraction. Where? In the object code? >> Do not sell a limitation of generics to a >> certain type of constraint as genuine advantage. > > From looking at generated code, the genuine advantage seems > to be the total absence of dispatching code. You don't need any code when dispatch is static. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de