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,43f6bd9b498b66d0 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: default formal parameters in generic declarations 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: <9b3bac4d-5ae1-4a1b-a81e-9aa9ae1843e0@e31g2000hse.googlegroups.com> <1qlkyebn1yxut$.1r1eauouyt3l8$.dlg@40tude.net> <47cbdde1$0$11000$9b4e6d93@newsspool4.arcor-online.net> Date: Mon, 3 Mar 2008 14:56:31 +0100 Message-ID: <1qe28uazlamg6.1i48owuthh2b7$.dlg@40tude.net> NNTP-Posting-Date: 03 Mar 2008 14:56:31 CET NNTP-Posting-Host: 6499c0ef.newsspool2.arcor-online.net X-Trace: DXC=U7bfU0IHoCffF8a^:6>b7eA9EHlD;3Ycb4Fo<]lROoRaFl8W>\BH3Yb?DTeKkb^_hcDNcfSJ;bb[eFCTGGVUmh?dLK[5LiR>kgb=0_VJ14@A7b X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:20172 Date: 2008-03-03T14:56:31+01:00 List-Id: On Mon, 03 Mar 2008 12:15:45 +0100, Georg Bauhaus wrote: > Dmitry A. Kazakov schrieb: > >> IMO, it is better (as always) to get rid of generics. Default values of >> packages are in fact inheritable interfaces. Thus inheritance should be the >> way. I would extend this part of the language rather than generics. > > Supposedly, removal of generics will also remove the > tags from concrete types? Only from non-by-reference ones. Actually Ada already has the keyword "tagged" which could read "do it by reference and please keep the tag." > How do you deal with what is now usually a generic > swap procedure? type Copyiable is interface ...; -- All the things with an assignment and copy constructor (initializer) A. Class-wide Swap procedure Swap (Left, Right : in out Copyiable'Class) is Temp : Copyiable'Class := Left; begin Left := Right; Right := Temp; end Swap; B. Primitive Swap (doubly-dispatching with only the diagonal elements allowed). procedure Swap (Left, Right : in out Copyiable) is Temp : Copyiable'Class := Left; begin Left := Right; Right := Temp; end Swap; P.S. One problem I didn't know how to solve was the constraints on the combinations of the argument's types. A generic solution is pre-constrained, so that it cannot handle some cases at all. For Swap you might wish to detect all non-diagonal cases which would raise Constraint_Error at compile time. Clearly, when the tags are known statically (as with generics) and (for the variant A) the body is inlined, for the variant B without the body, the compiler could give a warning. The problem is how to convert warning into an error. I guess that contracted exceptions could be a solution. P.P.S. Another problem is adding interfaces to existing types. This is solved by supertyping. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de