comp.lang.ada
 help / color / mirror / Atom feed
From: munnari.oz.au!yoyo.aarnet.edu.au!huon.itd.adelaide.edu.au!cs.adelaide.edu .au!andrewd@uunet.uu.net  (Andrew Dunstan)
Subject: Re: Generics?
Date: 9 Sep 92 05:26:34 GMT	[thread overview]
Message-ID: <18k1uaINN6su@huon.itd.adelaide.edu.au> (raw)

In article <6978@stan.xx.swin.oz.au>, rob@saturn.cs.swin.OZ.AU (Rob Allen) writ
es:
|> tp923021@jarrah.canberra.edu.au (Ben Elliston) writes:
|> >I've since moved onto making an array a generic type (such as this):
|> >GENERIC
|> >Type Index IS (<>);
|> >[..]
|> >Type Stack_Array IS Array(Index) of Character;
|> 
|> >Type Stack_Type IS RECORD
|> >  Data_Store: Stack_Array;
|> >  Pointer: Natural;
|> >END RECORD;
|> 
|> >As it stands now, it seems that since the "pointer" variable (which
|> >indicates the current "highwater" mark of the array) is a natural, that
|> >Ada won't allow a natural to access an array indexed by some unknown
|> >(generic) type.

[..]

|> If however you decide to keep Pointer as a Natural where 1 corresponds to
|> the first element then always use it as 
|>   X.Data_Store(Index'val(X.Pointer - 1 + Pos_1st))
|> where
|>   Pos_1st : constant := Index'pos(Index'first);
|> is to account for the likelihood that the actual Index is an arbitrary
|> subtype of a discrete type.  Using this approach the 'full' test is
|> X.Pointer = Index'length
|> Though none of the above code has been checked, I hope that helps.  rob


I'd like to see the code from which this is taken. If what is really wanted
is a stack, why is the index of the stack array a generic parameter? It
seems to me that the only generic type parameter for a stack type should
be the type stored - after all, the stack might not be implemented as an array
at all. I agree that Rob Allen's answer to the question is correct, but I
still want to know why the above is being attempted.

-- 
#######################################################################
#  Andrew Dunstan                   #   There's nothing good or bad   #
#  Department of Computer Science   #   but thinking makes it so.     #
#  University of Adelaide           #                                 #
#  South Australia                  #          - Shakespeare          #
#  net: andrewd@cs.adelaide.edu.au  #                                 #
#######################################################################

             reply	other threads:[~1992-09-09  5:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-09-09  5:26 Andrew Dunstan [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-07-02 22:33 Generics??? Michael Andersson
2001-07-02 17:48 ` Generics??? James Rogers
2001-07-02 18:54   ` Generics??? Ehud Lamm
2001-07-02 18:42 Generics??? Beard, Frank
2001-07-03 10:32 ` Generics??? Anders Wirzenius
2001-07-03 17:31   ` Generics??? Stephen Leake
2001-07-03 19:09   ` Generics??? tmoran
2001-07-04  5:30     ` Generics??? Anders Wirzenius
1992-09-14 15:00 Generics? cis.ohio-state.edu!zaphod.mps.ohio-state.edu!darwin.sura.net!jvnc.net!net
1992-09-09  1:34 Generics?  Rob Allen
replies disabled

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