From: Brian Drummond <brian@shapes.demon.co.uk>
Subject: Re: Experimenting with the OOP features in Ada
Date: Mon, 2 Jan 2017 14:43:25 -0000 (UTC)
Date: 2017-01-02T14:43:25+00:00 [thread overview]
Message-ID: <o4doud$rg3$1@dont-email.me> (raw)
In-Reply-To: o4dn2s$nj6$1@dont-email.me
On Mon, 02 Jan 2017 14:11:40 +0000, Brian Drummond wrote:
> On Mon, 02 Jan 2017 05:21:49 -0800, Laurent wrote:
>
> I suspect you intended something more like
>
> Test_Antibiotic := Base_Types.Antibiotics.Create_Name (Name => "Test
> Antibiotic 3");
> Test_Antibiotic.Set_Code_SIL (Code_SIL => "gen");
More specifically, especially if you're used to some other OO languages,
is that Ada (2005 and 2012) handle the object.method notation a little
differently than you may be used to.
You've written a function
function Create_Code_SIL (Code_SIL : String) return Object;
which takes ONE argument "Code_Sil" and creates a new object containing
it, and three empty elements...
You were probably expecting a silent "this" argument ... sorry, Ada
doesn't do that, you explicitly pass the receiver (or "self" or "this")
to the method (as the Linn Lingo language did).
So a function to set Code_SIL on an existing object would look more like
function Create_Code_SIL (This : Base_Types.Antibiotics.Objects;
Code_SIL : String) return Object;
and its implementation
function Create_Code_SIL (This : Base_Types.Antibiotics.Objects;
Code_SIL : String) return Object
is
begin
This.Code_SIL := My_Strings.Handle.Create (Value => Code_SIL);
return This;
end Create_Code_SIL;
or a Procedure version (the Set_* procedure in my previous post) with an
In Out parameter called This.
Procedure Set_Code_SIL (This : in out Base_Types.Antibiotics.Objects;
Code_SIL => "gen");
Now your function can be called either in traditional Ada-95 syntax with
both arguments in the argument list, or object.method notation with only
the second argument. This allows Ada-95 programs to be more easily and
gradually refactored into Ada-2005 or 2012.
So the following are equivalent:
Test_Antibiotic := Base_Types.Antibiotics.Create_Code_SIL (
This => Test_Antibiotic,
Code_SIL => "Test Antibiotic 3")
Test_Antibiotic := Test_Antibiotic.Create_Code_SIL
(Code_SIL => "Test Antibiotic 3");
but the preferred form would be
Test_Antibiotic.Set_Code_SIL (Code_SIL => "gen");
-- Brian
next prev parent reply other threads:[~2017-01-02 14:43 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-02 13:21 Experimenting with the OOP features in Ada Laurent
2017-01-02 14:11 ` Brian Drummond
2017-01-02 14:43 ` Brian Drummond [this message]
2017-01-02 16:27 ` Laurent
2017-01-03 13:01 ` Brian Drummond
2017-01-03 13:57 ` Laurent
2017-01-03 14:31 ` Dmitry A. Kazakov
2017-01-03 17:07 ` G.B.
2017-01-03 20:42 ` Dmitry A. Kazakov
2017-01-04 12:18 ` Laurent
2017-01-04 12:44 ` Dmitry A. Kazakov
2017-01-05 11:41 ` Laurent
2017-01-05 13:02 ` Dmitry A. Kazakov
2017-01-05 13:11 ` AdaMagica
2017-01-04 15:09 ` Shark8
2017-01-05 11:54 ` Laurent
[not found] ` <85ef59f3-bcbe-4630-9b4d-8285623ab456@googlegroups.com>
2017-01-03 12:48 ` Brian Drummond
2017-01-03 13:43 ` Laurent
2017-01-02 15:54 ` Laurent
2017-01-02 16:41 ` Dmitry A. Kazakov
2017-01-02 18:50 ` Laurent
2017-01-02 20:55 ` Dmitry A. Kazakov
2017-01-03 13:39 ` Laurent
2017-01-03 14:40 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox