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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,103b407e8b68350b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-16 20:00:42 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn14feed!worldnet.att.net!207.217.77.102!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!harp.news.atl.earthlink.net!not-for-mail From: Richard Riehle Newsgroups: comp.lang.ada Subject: Re: Anybody in US using ADA ? One silly idea.. Date: Thu, 16 Jan 2003 20:09:53 -0800 Organization: AdaWorks Software Engineering Message-ID: <3E278211.95858B58@adaworks.com> References: <1041908422.928308@master.nyc.kbcfp.com> <1041997309.165001@master.nyc.kbcfp.com> <1042086217.253468@master.nyc.kbcfp.com> <1042477504.547640@master.nyc.kbcfp.com> <1042651417.215661@master.nyc.kbcfp.com> <1042743579.1165@master.nyc.kbcfp.com> Reply-To: richard@adaworks.com NNTP-Posting-Host: 41.b2.48.2b Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Server-Date: 17 Jan 2003 04:00:41 GMT X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:33114 Date: 2003-01-17T04:00:41+00:00 List-Id: Hyman Rosen wrote: > The advantage is that more efficient (smaller/faster) code > can be generated from generics, if not in theory then certainly > in practice. Programming languages are not just abstract > constructs, they are means for generating sequences of native > machine code to perform some task. Bill Findlay posted some code earlier, that I revised slightly to make a point in this conversation. Here is another example using generics. with Ada.Text_IO; with Ada.Integer_Text_IO; with System; use Ada; procedure Conditional_Instantiation is X : Character := ' '; type Large_Number is range System.Min_Int..System.Max_Int; Bound : Large_Number := Large_Number'Last; begin loop Text_IO.Put("Enter a Character: "); Text_IO.Get(X); Text_IO.New_Line; if X in 'A'..'Z' or X in 'a'..'z' then Text_IO.Put("Enter a number: "); Integer_Text_IO.Get(Integer(Bound)); declare type Number is new Large_Number range 1..Bound; package IIO is new Text_IO.Integer_IO(Num => Number); begin Text_IO.Put("Upper Bound - 1 = "); IIO.Put(Number'Last - 1); Text_IO.New_Line; end; else exit; end if; end loop; end Conditional_Instantiation; Note that the result of the IIO.Put statement will reflect the value of one less than whatever has been selected for the value of Bound in the type declaration. This will only work on derived types and subtypes, but that is good enough for most kind of applications. Richard Riehle