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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,604e0f87aa06eab6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-03-28 05:34:06 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Imitation is the sincerest form of flattery Date: Fri, 28 Mar 2003 14:34:05 +0100 Message-ID: References: <5115eb96.0303220201.44527637@posting.google.com> <5115eb96.0303232053.2fcc7d78@posting.google.com> <5115eb96.0303242148.57027600@posting.google.com> <6Y_fa.5102$kU.534@nwrdny01.gnilink.net> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1048858445 889169 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:35787 Date: 2003-03-28T14:34:05+01:00 List-Id: On Thu, 27 Mar 2003 19:45:42 GMT, "Frank J. Lhota" wrote: >"Dmitry A. Kazakov" wrote in message >news:b5qcnq$2bshmf$1@ID-77047.news.dfncis.de... >> Frank J. Lhota wrote: >> >> > I wish that we had the following functions defined in the Standard >> > package: >> > >> > function Pred( X : Integer ) return Integer; >> > function Max( X, Y : Integer ) return Integer; >> > -- etc. >> > >> > This would allow the programmer to re-define any of these attributes for >> > types derived from Integer (or other predefined types). >> >> True, but it is a very long way to go. For example, to have 'Max >> dispatching, you would immediately need true multiple dispatch - it has >two >> parameters! > >AFAIK (and my testing seems to confirm this) if we have the function > > function Max( X, Y : An_Integer_Type ) return An_Integer_Type; > >defined in the same package as An_Integer_Type, and if we derive a type >New_Integer from An_Integer_Type, i.e. > > type New_Integer is new An_Integer_Type; > >then New_Integer inherits Max from An_Integer_Type, i.e. there is an >implicit function > > function Max( X, Y : New_Integer ) return New_Integer; > >that the programmer can either call or replace with his own version. This is absolutely another story. type A is new B, "clones" types. The result is a new type which is same as B. From this point of view Max is not inherited by New_Integer. Consider: X : Integer; Y : New_Integer; Max (X, Y); -- Illegal! Should Max be inherited Max (X, Y) would be legal. BTW it is pitty that type cloning is not allowed for tagged types. IMO this restriction should be removed. >Multiple dispatching would only be an issue if we wanted to generate a >version of Max that compares and / or returns different integer types. By >the very nature of the Max function, we are unlikely to even want to do >that. My point is *IF*: 1. Inheritance has to be supported for all types in the sense that Integer'Class might refer to descendants of Integer 2. The attributes has to be declared as primitive operations Then you have to support MD for all attributes with several arguments. So 'Max would be declared as: function 'Max (Left, Right : Integer) return Integer'Class; There is no other choice. The present situation when tags of both arguments has to be same is unsatisfactory. It is not so bad now, because the tagged types are too heavy (passed by reference, have embedded tag) to use them for representation of numeric things. There binary operations are very common. Should you make OO available there, this will become a problem: function 'Max (Left : Integer; Right : Integer'Class) return Integer'Class; + manual dispatch on Right is awful! >This is not to dismiss the utility of multiple dispatching, but >unfortunately most OOPL's avoid it because of efficiency concerns. There are many problems with MD, but I do not think that efficiency is a big issue. It will probably cost one indirection more. --- Regards, Dmitry Kazakov www.dmitry-kazakov.de