comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <bauhaus@futureapps.de>
Subject: Re: Help needed for ada package
Date: Tue, 02 Aug 2005 18:37:21 +0200
Date: 2005-08-02T18:37:14+02:00	[thread overview]
Message-ID: <42efa139$0$11745$9b4e6d93@newsread4.arcor-online.net> (raw)
In-Reply-To: <1122997736.667017.104140@o13g2000cwo.googlegroups.com>

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 => ...);




  parent reply	other threads:[~2005-08-02 16:37 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1122305318.728942.304120@f14g2000cwb.googlegroups.com>
2005-07-25 17:45 ` Help needed for ada package Marc A. Criley
2005-07-25 17:47 ` Simon Clubley
2005-07-25 18:21   ` Georg Bauhaus
2005-07-25 18:46 ` Frank J. Lhota
2005-07-25 19:26 ` tmoran
2005-07-25 22:12 ` Ludovic Brenta
2005-07-25 23:33 ` Jeffrey Carter
2005-07-26 17:29   ` Pascal Obry
2005-07-26 19:03     ` Ed Falis
2005-07-26 19:05       ` Pascal Obry
2005-07-26 22:20     ` Jeffrey Carter
2005-07-27  9:07       ` Georg Bauhaus
2005-08-01  5:37     ` Dave Thompson
2005-08-01 12:37       ` Adrien Plisson
2005-07-26  3:17 ` Steve
     [not found]   ` <1122475184.849564.159870@g44g2000cwa.googlegroups.com>
2005-07-27 17:13     ` Martin Krischik
2005-07-27 18:03     ` Simon Wright
2005-07-28  0:58       ` Jeffrey Carter
2005-07-28  1:53         ` tmoran
2005-07-28 16:21           ` Jeffrey Carter
2005-07-28  2:27     ` Steve
     [not found]       ` <1122547648.069514.63520@g14g2000cwa.googlegroups.com>
2005-07-28 18:33         ` Ludovic Brenta
2005-07-28 19:51           ` tmoran
     [not found]           ` <uaaje1d0l4tp1kjs18mkrgfmbkcir308bt@4ax.com>
2005-07-29  8:37             ` tmoran
2005-07-30  1:44             ` Steve
2005-07-29  1:57         ` Steve
     [not found]           ` <1122980923.842598.181310@g49g2000cwa.googlegroups.com>
2005-08-02 11:37             ` Adrien Plisson
2005-08-02 12:05             ` Georg Bauhaus
     [not found]               ` <1122986293.760710.320180@g44g2000cwa.googlegroups.com>
2005-08-02 13:19                 ` Adrien Plisson
2005-08-02 14:26                 ` Georg Bauhaus
     [not found]                   ` <1122995870.689997.66000@g44g2000cwa.googlegroups.com>
2005-08-02 15:38                     ` Georg Bauhaus
     [not found]                       ` <1122997736.667017.104140@o13g2000cwo.googlegroups.com>
2005-08-02 16:37                         ` Georg Bauhaus [this message]
2005-08-02 16:52             ` Jeffrey Carter
     [not found]             ` <o04ve11odsjs756915g5eonn0g1guopih2@4ax.com>
2005-08-02 23:21               ` tmoran
     [not found]               ` <1123069124.562944.246730@o13g2000cwo.googlegroups.com>
2005-08-03 12:08                 ` Georg Bauhaus
2005-08-03 16:13                   ` Jeffrey Carter
2005-08-03 17:57                     ` Georg Bauhaus
2005-08-03 16:48                   ` Martin Dowie
     [not found]                   ` <1123084562.854161.299550@g44g2000cwa.googlegroups.com>
2005-08-03 17:58                     ` Georg Bauhaus
     [not found]                 ` <n0o1f1lqsbi23bt7b2li6oc85r7pgfn9d5@4ax.com>
     [not found]                   ` <1123090742.323338.311230@f14g2000cwb.googlegroups.com>
2005-08-03 18:07                     ` Georg Bauhaus
2005-08-03 20:18                     ` Simon Wright
2005-08-04  0:59                       ` Jeffrey Carter
2005-08-04  5:42                         ` Simon Wright
     [not found]   ` <1123173235.773051.23360@z14g2000cwz.googlegroups.com>
2005-08-04 16:50     ` Simon Clubley
     [not found]       ` <1123174747.107994.317580@o13g2000cwo.googlegroups.com>
2005-08-04 16:27         ` Georg Bauhaus
2005-08-04 20:14         ` Simon Wright
     [not found] <1122320036.858648.242630@f14g2000cwb.googlegroups.com>
2005-07-26  0:47 ` tmoran
     [not found] <1122372224.124606.271380@f14g2000cwb.googlegroups.com>
2005-07-26 17:31 ` tmoran
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox