home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!yoyo.aarnet.edu.au!huon.itd.adelaide.edu.au!cs.adelaide.edu.au!andrewd
- From: andrewd@cs.adelaide.edu.au (Andrew Dunstan)
- Newsgroups: comp.lang.ada
- Subject: Re: Generics?
- Message-ID: <18k1uaINN6su@huon.itd.adelaide.edu.au>
- Date: 9 Sep 92 05:26:34 GMT
- References: <tp923021.715953043@jarrah> <6978@stan.xx.swin.oz.au>
- Organization: The University of Adelaide
- Lines: 46
- NNTP-Posting-Host: achilles.cs.adelaide.edu.au
-
- In article <6978@stan.xx.swin.oz.au>, rob@saturn.cs.swin.OZ.AU (Rob Allen) writes:
- |> 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 # #
- #######################################################################
-