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-Thread: 103376,bc4137777a63bff X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!proxad.net!newsfeed.arcor.de!news.arcor.de!not-for-mail Date: Tue, 02 Aug 2005 18:37:21 +0200 From: Georg Bauhaus Organization: future apps GmbH User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050513 Debian/1.7.8-1 X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Help needed for ada package References: <1122305318.728942.304120@f14g2000cwb.googlegroups.com> <2OudnZo-iL1aN3jfRVn-iQ@comcast.com> <1122475184.849564.159870@g44g2000cwa.googlegroups.com> <1122547648.069514.63520@g14g2000cwa.googlegroups.com> <1122980923.842598.181310@g49g2000cwa.googlegroups.com> <42ef619c$0$6984$9b4e6d93@newsread2.arcor-online.net> <1122986293.760710.320180@g44g2000cwa.googlegroups.com> <42ef829c$0$11744$9b4e6d93@newsread4.arcor-online.net> <1122995870.689997.66000@g44g2000cwa.googlegroups.com> <42ef9376$0$11759$9b4e6d93@newsread4.arcor-online.net> <1122997736.667017.104140@o13g2000cwo.googlegroups.com> In-Reply-To: <1122997736.667017.104140@o13g2000cwo.googlegroups.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <42efa139$0$11745$9b4e6d93@newsread4.arcor-online.net> NNTP-Posting-Date: 02 Aug 2005 18:37:14 MEST NNTP-Posting-Host: f2288a3b.newsread4.arcor-online.net X-Trace: DXC=953m5CAn=cVUEj^fn36YV^:ejgIfPPldTjW\KbG]kaMX]kI_X=5KeaV7ghVf]mU]jTUUng9_FXZ=S>:=P9Ihe`BX@Z?dZ]MOidU X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:3906 Date: 2005-08-02T18:37:14+02:00 List-Id: strictly_mk@hotmail.com wrote: > is there a more appropriate type that > wont upset the rest of the program? Use one of Ada's formal types. That is, specify what the generic needs as a type using the syntax for formal types. Examples generic type T is range <>; package Pack ... In this case the formal type T says, if you want to make an instance of this generic package, you have to provide a signed integer type as the (actual) type to be used in the created instance, as in package Foo is new Pack (T => Integer); Integer is a signed integer type, as are Natural, or Long_Integer. When you instantiate Pack, you can choose the type to be used. When you write the generic package, you only specify some assumptions about the possible types. In this case, "range <>" specifies "some signed integer type". Given these possible assumptions about T, you can use T in expressions, without knowing what T is going to be in some instance of the generic package. Like T'First (the first of the values in T's range). You can add values of T because T denotes some integer type, no matter which one actually, later. Another example is generic type T is (<>); package Pack2 ... In this case formal type T says, if you want to make an instance of this generic package, you have to provide a discrete type as the (actual) type to be used in the created instance. Discrete types are either integer types or enumeration types. Just no real types. So if you had, somewhere type Family is (Jack, Jakub, Florentina, Marge, Bart); i.e. an enumeration type, you could say package Foo2 is new Pack2 (T => Family); Inside Pack2 (the generic) you can use T just like you use any enumeration type. For example, you can say T'First, but you cannot add values, because this doesn't work for enumeration types. When you write the package, you know you can assume T is denoting an enumeration type, but not which one. Because that is decided when someone, possibly you, instantiate Pack2. Last, when you have generic type ID is new Long_Integer; package PoP ... the choice of types to be used when instantiating is pretty fixed. Only types derived from Long_Integer (includes Long_Integer) or subtypes thereof can be filled in when you write package My_PoP_Instance is new PoP(ID => ...);