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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Brian Drummond Newsgroups: comp.lang.ada Subject: Re: Experimenting with the OOP features in Ada Date: Mon, 2 Jan 2017 14:43:25 -0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <29380aa7-0c3b-4908-94c6-aa91f3996b42@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 2 Jan 2017 14:43:25 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="6c1c38fcc435c066e6d8e3c9711220ef"; logging-data="28163"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180dCL5tnYcxD4CfFi7gClmVubtsu08c0Q=" User-Agent: Pan/0.140 (Chocolate Salty Balls; GIT b8fc14e git.gnome.org/git/pan2) Cancel-Lock: sha1:H6JPeMCwvewjJVPZGSApwgBgjb4= Xref: news.eternal-september.org comp.lang.ada:32996 Date: 2017-01-02T14:43:25+00:00 List-Id: 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