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=-1.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,622fd11f5eb54423 X-Google-Attributes: gid103376,public From: johnherro@aol.com (John Herro) Subject: Re: how to make a package???? Date: 1996/08/15 Message-ID: <4uvec2$nrf@newsbf02.news.aol.com>#1/1 X-Deja-AN: 174362520 sender: root@newsbf02.news.aol.com references: <4uu2kp$32u@news.us.net> organization: America Online, Inc. (1-800-827-6364) newsgroups: comp.lang.ada Date: 1996-08-15T00:00:00+00:00 List-Id: mhall59@us.net (Michael W. Hall) asks about converting a Sqrt function to a package. Your Sqrt function is excellent as it stands. You wouldn't *convert* it to a package, but you would *move* it into a new package. That way, other programs besides your Square_Root could make use of your excellent Sqrt function. Here's how to move your function into a new package: package Math is -- This is the package specification. function Sqrt (Value : in Float) return Float; -- You could add other subprogram specifications here. end Math; package body Math is -- This is the package body. function Sqrt (Value : in Float) return Float is ... end Sqrt; -- The bodies of any other subprograms would go here. end Math; with Text_IO, Math; -- Your main program. procedure Square_Root is package Float_IO is new Text_IO.Float_IO (Num => Float); begin Float_IO.Put (Math.Sqrt (16.0)); Text_IO.New_Line; Float_IO.Put (Math.Sqrt (15.0)); Text_IO.New_Line; end Square_Root; You must compile the package specification first, but you can compile either the package body or the main program second. Most compilers will let you put all three parts into one file and compile that, but the package specification must come first. Now other programs that need Sqrt can "with" your Math package and gain access to Sqrt. There's much more to packages. For example, the above package can be improved by using "is separate." Packages can also help contain the effects of certain changes, so they affect only a small part of your program. For more information, you can download my Ada Tutor program from the Web or FTP site below my signature. Besides more information on packages, it has a sample Sqrt function similar to yours, but generic so that it can be used with other floating point types besides the standard Float. Also, feel free to ask more questions here. You'll find the people in comp.lang.ada eager to help. - John Herro Software Innovations Technology http://members.aol.com/AdaTutor ftp://members.aol.com/AdaTutor