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 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: Re: Instantiating package problems Date: Mon, 4 Jan 2016 14:43:20 +0100 Organization: A noiseless patient Spider Message-ID: References: <7dcd49f3-b04f-4ea3-b431-5c27f73b9afe@googlegroups.com> <87poxixqmy.fsf@theworld.com> Reply-To: nonlegitur@futureapps.de Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 4 Jan 2016 13:40:42 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="b96887e80893c84a90c3007226ca0d1c"; logging-data="22051"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19JXlbODFY6bjrCSgaU1FCYCNFoLLKgfBg=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 In-Reply-To: Cancel-Lock: sha1:EqZ94Uhl/4J2D8lEKIctHU/HuKY= Xref: news.eternal-september.org comp.lang.ada:29006 Date: 2016-01-04T14:43:20+01:00 List-Id: On 04.01.16 01:30, Andrew Shvets wrote: > Ok, I think I understand. In Ada, every vanilla package imports all of the public functions/procedures to be used and can be thought of as static functions in C++. However, I can create instances of different records in order to retain an element of state like I would in C++ when I create an object. > Consider this, just for some wording. with Energy, Physics; package Named_Things is function Consumption return Physics.Mass; -- equivalent of total energy transformed by traffic. type Car is private; procedure Method_1 (The_Object : in out Car; Amount : in Energy.Fuel); function Method_2 (The_Object : in Car) return Physics.Velocity; type Roadkill is (Squirrels, Cats, Rat, Opossums, Raccoons, Dogs, Deer); procedure Hit (Object_A : Roadkill; Object_B : Car); -- adds to goods consumed by traffic. private Total_Consumption : Physics.Litres; -- burned by all cars, cf. Method_1, also equiv. Hit type Car is record Fill : Energy.Fuel; -- ... end record; end Named_Things; Subprograms Method_1 and Method_2 belong to the primitive operations of type Car, declared next to it as primitive subprograms. All three, the type Car and its primitive subprograms, are declared in package Named_Things. Creating an object of type Car, My_Car : Named_Things.Car; gives an instance of the type Car, for state; calling Method_1 and passing this instance as the first argument makes Method_1 operate on this object (formally, on the type, I think); additionally, the body of Method_1 may assign a new value to the variable Named_Things.Total_Consumption. However, the package also has the declaration of another type and two more procedures. One of them is referring to both types in its parameter profile, viz. Hit.