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.1 required=5.0 tests=AXB_XMAILER_MIMEOLE_OL_024C2, BAYES_00,MAILING_LIST_MULTI,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d8c487e59f13ecdf X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-09 11:57:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!isdnet!137.194.32.100.MISMATCH!enst.fr!not-for-mail From: "David C. Hoos" Newsgroups: comp.lang.ada Subject: Re: Ada Basics Date: Wed, 9 Oct 2002 13:58:47 -0500 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: References: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 1034189822 88136 137.194.161.2 (9 Oct 2002 18:57:02 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Wed, 9 Oct 2002 18:57:02 +0000 (UTC) Return-Path: X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.13 Precedence: bulk List-Unsubscribe: , List-Id: comp.lang.ada mail<->news gateway List-Post: List-Help: List-Subscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Original-Cc: mheaney@on2.com Xref: archiver1.google.com comp.lang.ada:29636 Date: 2002-10-09T13:58:47-05:00 Where is the procedure Increment declared? ----- Original Message ----- From: "Matthew Heaney" Newsgroups: comp.lang.ada To: Sent: Wednesday, October 09, 2002 1:37 PM Subject: Re: Ada Basics > > "prashna" wrote in message > news:d40d7104.0210090453.f6aed66@posting.google.com... > > Hi all, > > What is the difference between declaring a type by using new (ex type > > one_to_hundred is new Integer range 1..100) and declaring a type > > without using new (type one_to_hundred is range 1..100)? > > As has been pointed out, the new form indicates derivation, which means the > primitive operations of the parent type are inherited by the derived type. > > For type Integer, it's not obvious what's happening, but consider another > type: > > package P is > type T is range 0 .. 200; > procedure Inc (O : in out T); > end; > > Here, we have an integer type, that has (in addition to the pre-defined > operations for integer types) an increment operation, allowing you to do > this: > > X : T := 0; > Increment (X); > > Now let's create another type that derives from T: > > with P; > package Q is > type NT is new P.T; --range is 0 .. 200 > end; > > Type NT inherits the operations of its parent type T, which means NT has an > increment operation: > > Y : NT := 0; > Increment (Y); > > In this example, T is the root of a family of types, and all types in this > family have an Inc operation. This is useful if you want to pass any member > of this family as a generic formal type: > > with P; > generic > type NT is new P.T; > package GR is ...; > > In this example, you can instantiate GR with either P.T or Q.NT: > > with P; > package R is new GR (P.T); > > with Q; > package R is new GR (Q.NT); > > In the body of GR, you can apply the Inc operation to objects of formal type > NT. > > For scalar types, you're allowed to constrain the range of the parent. In > the example above, NT has the same range as its parent (0 .. 200), but we > could have made it smaller if that were desired: > > with P; > package Q is > type NT is new T range 1 .. 100; --constrain range > end; > > In general, a derivation is allowing you to state that there is a > relationship between the types. If no such relationship is necessary, then > just declare the type without a derivation: > > package Q is > type T is range 0 .. 200; > end; > > > > > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada.eu.org > http://ada.eu.org/mailman/listinfo/comp.lang.ada >