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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!feeder5.feed.usenet.farm!feed.usenet.farm!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost2.xs4all.net!news.kpn.nl!not-for-mail Subject: Re: Using Generic Pasckages To: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada References: <5e8edf69$0$18432$e4fe514c@news.kpn.nl> From: ldries46 Message-ID: Date: Thu, 9 Apr 2020 12:05:37 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: nl NNTP-Posting-Host: 729eea6f.news.kpn.nl X-Trace: G=ZBE7ZZAT,C=U2FsdGVkX18vx36wnmzJrx+emg1oV+2CBJWEyaDEEVTIuemrLP185mM69UmHK3yX0N1eBgg1WZ4Xx+KK7Jo0lWreuztejjdoPi4ij7CljqA= X-Complaints-To: abuse@kpn.nl Xref: reader01.eternal-september.org comp.lang.ada:58334 Date: 2020-04-09T12:05:37+02:00 List-Id: Op 9-4-2020 om 10:57 schreef Dmitry A. Kazakov: > On 2020-04-09 10:40, ldries46 wrote: >> I have created some generic packages. tese are packages that only do >> the same thing but with other types. Till now I did only need these >> packages without interaction with between packages using the same >> type. I just can declare them: >> Package AA is new BB(type); then calling them as >> A := AA.Get_Value; >> No other declaration seemed to be neccesary . >> >> Now I have the following situation: >> Package AA is new BB(integer); >> Package CC is new BB(integer); >> and a case where I have several statements using Package AA in one >> condition and CC the other case. >> I want  to do that by using: >> if D then EE := AA; else EE := CC; end if; >> But I cannot find in the documentation  how the declaration of EE >> should be made. >> >> Of course there is the possibility to create the same progrram >> without using EE but that is far less readable and thus creating more >> possible errors. >> >> If I have to do this without the generic packages I already have the >> program alse will be less readable. > > What you are observing is the advantages of dynamic polymorphism > (tagged types) over the static one (generics). > > Already the name static hints that you cannot select a polymorphic > implementation (AA or CC) using some non-static (dynamic) expression D. > I am using Generic because in the program the same routines should be possible for several different types, but now I have also a situation where two instantiations of the same type should be used under some conditions. For instance in a instantiation of a buffer of Unbounded.String's depending on the condition one of two should be used, but the buffer should also be used for another type