home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / ada / 2564 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  2.5 KB

  1. Path: sparky!uunet!munnari.oz.au!yoyo.aarnet.edu.au!huon.itd.adelaide.edu.au!cs.adelaide.edu.au!andrewd
  2. From: andrewd@cs.adelaide.edu.au (Andrew Dunstan)
  3. Newsgroups: comp.lang.ada
  4. Subject: Re: Generics?
  5. Message-ID: <18k1uaINN6su@huon.itd.adelaide.edu.au>
  6. Date: 9 Sep 92 05:26:34 GMT
  7. References: <tp923021.715953043@jarrah> <6978@stan.xx.swin.oz.au>
  8. Organization: The University of Adelaide
  9. Lines: 46
  10. NNTP-Posting-Host: achilles.cs.adelaide.edu.au
  11.  
  12. In article <6978@stan.xx.swin.oz.au>, rob@saturn.cs.swin.OZ.AU (Rob Allen) writes:
  13. |> tp923021@jarrah.canberra.edu.au (Ben Elliston) writes:
  14. |> >I've since moved onto making an array a generic type (such as this):
  15. |> >GENERIC
  16. |> >Type Index IS (<>);
  17. |> >[..]
  18. |> >Type Stack_Array IS Array(Index) of Character;
  19. |> 
  20. |> >Type Stack_Type IS RECORD
  21. |> >  Data_Store: Stack_Array;
  22. |> >  Pointer: Natural;
  23. |> >END RECORD;
  24. |> 
  25. |> >As it stands now, it seems that since the "pointer" variable (which
  26. |> >indicates the current "highwater" mark of the array) is a natural, that
  27. |> >Ada won't allow a natural to access an array indexed by some unknown
  28. |> >(generic) type.
  29.  
  30. [..]
  31.  
  32. |> If however you decide to keep Pointer as a Natural where 1 corresponds to
  33. |> the first element then always use it as 
  34. |>   X.Data_Store(Index'val(X.Pointer - 1 + Pos_1st))
  35. |> where
  36. |>   Pos_1st : constant := Index'pos(Index'first);
  37. |> is to account for the likelihood that the actual Index is an arbitrary
  38. |> subtype of a discrete type.  Using this approach the 'full' test is
  39. |> X.Pointer = Index'length
  40. |> Though none of the above code has been checked, I hope that helps.  rob
  41.  
  42.  
  43. I'd like to see the code from which this is taken. If what is really wanted
  44. is a stack, why is the index of the stack array a generic parameter? It
  45. seems to me that the only generic type parameter for a stack type should
  46. be the type stored - after all, the stack might not be implemented as an array
  47. at all. I agree that Rob Allen's answer to the question is correct, but I
  48. still want to know why the above is being attempted.
  49.  
  50. -- 
  51. #######################################################################
  52. #  Andrew Dunstan                   #   There's nothing good or bad   #
  53. #  Department of Computer Science   #   but thinking makes it so.     #
  54. #  University of Adelaide           #                                 #
  55. #  South Australia                  #          - Shakespeare          #
  56. #  net: andrewd@cs.adelaide.edu.au  #                                 #
  57. #######################################################################
  58.