From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: Instantiating package problems
Date: Mon, 4 Jan 2016 14:43:20 +0100
Date: 2016-01-04T14:43:20+01:00 [thread overview]
Message-ID: <n6dsop$lh3$1@dont-email.me> (raw)
In-Reply-To: <f892b7ca-744f-4ed3-8f77-a596c2e291ca@googlegroups.com>
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.
next prev parent reply other threads:[~2016-01-04 13:43 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-03 18:40 Instantiating package problems Andrew Shvets
2016-01-03 20:27 ` Georg Bauhaus
2016-01-03 21:21 ` Andrew Shvets
2016-01-03 21:04 ` Jeffrey R. Carter
2016-01-03 21:27 ` Andrew Shvets
2016-01-03 22:39 ` Jeffrey R. Carter
2016-01-03 22:08 ` Bob Duff
2016-01-04 0:07 ` Andrew Shvets
2016-01-04 0:30 ` Andrew Shvets
2016-01-04 13:43 ` G.B. [this message]
2016-01-04 14:23 ` Brian Drummond
2016-01-04 20:49 ` Anh Vo
2016-01-04 21:10 ` Dmitry A. Kazakov
2016-01-04 22:39 ` Anh Vo
2016-01-05 1:42 ` Anh Vo
2016-01-05 7:35 ` Dmitry A. Kazakov
2016-01-06 2:46 ` Andrew Shvets
2016-01-06 8:53 ` Dmitry A. Kazakov
2016-01-06 3:30 ` Andrew Shvets
2016-01-06 4:51 ` Anh Vo
2016-01-06 4:54 ` Anh Vo
2016-01-06 5:00 ` Andrew Shvets
2016-01-06 5:07 ` Anh Vo
2016-01-07 4:41 ` Andrew Shvets
2016-01-07 5:41 ` Anh Vo
2016-01-09 20:14 ` Andrew Shvets
2016-01-10 19:43 ` Andrew Shvets
2016-01-10 21:38 ` Jeffrey R. Carter
2016-01-10 21:50 ` Georg Bauhaus
2016-01-10 21:58 ` Andrew Shvets
2016-01-06 13:07 ` G.B.
2016-01-07 4:42 ` Andrew Shvets
2016-01-06 14:25 ` Bob Duff
2016-01-06 23:48 ` Anh Vo
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox