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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,c02604a46964120 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder.news-service.com!novso.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Noob question: universal_integer type Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <85pemlFod9U1@mid.individual.net> <7DQJn.4466$Z6.1110@edtnps82> Date: Sat, 22 May 2010 15:47:28 +0200 Message-ID: NNTP-Posting-Date: 22 May 2010 15:47:28 CEST NNTP-Posting-Host: a147d206.newsspool1.arcor-online.net X-Trace: DXC=`;l51[h2=O?]E=H1Q9`787ic==]BZ:af>4Fo<]lROoR1<`=YMgDjhg2XeEk@>I_9L8[6LHn;2LCV>[< X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:11883 Date: 2010-05-22T15:47:28+02:00 List-Id: On Sat, 22 May 2010 13:04:03 GMT, Duke Normandin wrote: > On 2010-05-22, Niklas Holsti wrote: >> Perhaps it is also worth mentioning that Ada does have a way of >> explicitly indicating the type to be chosen for a literal, by >> "qualifying" it with a type name. This can be necessary to resolve >> overloaded operation names. For example, assume that you define two >> integer types: >> >> type Apples is range 0 .. 20; >> type Ants is range 0 .. 1_000_000; >> >> and then define a procedure "Eat" for each type, with different content >> for eating apples and for eating ants: >> >> procedure Eat (Items : Apples) ... end Eat; >> >> procedure Eat (Items : Ants) ... end Eat; >> >> A call of Eat with a literal parameter, for example Eat (17), is then >> ambiguous (and the compiler will tell you so). To show if you are eating >> apples or ants, you qualify the literal with the type name and an >> apostrophe, as in >> >> Eat (Apples'(17)); >> >> for eating 17 apples, or >> >> Eat (Ants'(17)) >> >> for eating 17 ants. Since the type of the parameter is now explicit, the >> compiler knows which procedure Eat is to be called. > > I love it! and the compiler would choke with an "out of bounds" exception if > you called Eat (Apples'(25)); - if I understand the Coronado tutorial > correctly. Thanks for the input... Yes, the Constraint_Error exception. But note, this is OK: Eat (Apples'(25 - 10)); This is another reason behind universal types. You can perform computations on them ignoring constraints of the particular type. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de