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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a718bcdc37ac6307,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-10-25 18:17:26 PST Path: nntp.gmd.de!xlink.net!fauern!news.th-darmstadt.de!terra.wiwi.uni-frankfurt.de!zeus.rbi.informatik.uni-frankfurt.de!news.dfn.de!Germany.EU.net!EU.net!uunet!world!blanket.mitre.org!linus.mitre.org!linus!mbunix!eachus From: eachus@spectre.mitre.org (Robert I. Eachus) Newsgroups: comp.lang.ada Subject: Re: derived types, constants and literals Date: 24 Oct 94 16:05:11 Organization: The Mitre Corp., Bedford, MA. Message-ID: References: NNTP-Posting-Host: spectre.mitre.org In-reply-to: leschkes@ferret.cig.mot.com's message of 24 Oct 94 16:34:40 GMT Date: 1994-10-24T16:05:11+00:00 List-Id: In article leschkes@ferret.cig.mot.com (Scott Leschke) writes: > In Ada 83' constants of a type were not derived along with the > operations on that type. For example: > package Test1 is > type X is range 0..100; > Null_Val : constant X := 0; > procedure DoIt(Val : in X := Null_Val); > end Test1; > with Test1; > package Test2 is > type Y is new Test1.X; > B : constant Y := Null_Val; -- doesn't compile > -- B : constant Y := Y(Test1.Null_Val); -- compiles > end Test2; Did you think to try: function Null_Val returns X? Now B: constant Y := Null_Val; works just fine in both Ada 83 and Ada 9X. In Ada a lot of things that you normally think of as constants (character literals and enumeration literals for example) are defined as functions to get the appropriate behavior. Just accept the fact that an Ada constant is not a C constant or a FORTRAN constant, and an Ada function is different from a C function or a FORTRAN function and you won't have a problem. (Ada constants don't even have to be statically sized, let alone have static values, whereas some Ada functions are defined to be static.) > It always struck me as odd that in Ada83, constants of a type could > not be derived and overridden just like operations were. Since theyb > aren't, one of two possibilities exists for procedure Test2.DoIt. > Either it is derived as: > procedure DoIt(Val : Y := Y(Test1.Null_Val));... Got it the first time. In some cases this conversion may be more than just a view conversion. -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...