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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2f1406ca802cdec5,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsfeed.pacific.net.au!nasal.pacific.net.au!not-for-mail Newsgroups: comp.lang.ada Subject: Aliasing or referencing assignment From: David Trudgett Organization: Very little? Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:YxTzHrNxz2Dnr2kdY+Qvw7AXBvw= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 09 Sep 2005 10:20:45 +1000 NNTP-Posting-Host: 61.8.40.214 X-Complaints-To: news@pacific.net.au X-Trace: nasal.pacific.net.au 1126225518 61.8.40.214 (Fri, 09 Sep 2005 10:25:18 EST) NNTP-Posting-Date: Fri, 09 Sep 2005 10:25:18 EST Xref: g2news1.google.com comp.lang.ada:4538 Date: 2005-09-09T10:20:45+10:00 List-Id: I'm having a little difficulty with assign by reference and assign by value (copy) semantics in a piece of code I'm working on. In the chunk of code that follows below, I want to avoid repeating "Self.List(Opponent_Win, Can_I_Play)" many times, and just replace it with a variable name like "C". "Self.List(Opponent_Win, Can_I_Play)" returns a Charles container library Vector of Unbounded_String. The assignment: C := Self.List(Opponent_Win, Can_I_Play); -- "List" is 2D array is ineffective in doing what I want because it is doing a value copy. I've tried to turn the type definition of "C" into an access type, but with no success. I also tried the "To_Access" function (in charles.vectors.unbounded), but that returns a reference to an "Element_Array" and not a Container_Type with which I can use "Append". Anyway, here is the code: procedure Initialize (Self : in out Comments) is C : String_List.Container_Type; package Random_Integer is new Ada.Numerics.Discrete_Random(Integer); use Random_Integer; G : Generator; begin Reset(G); Ada.Numerics.Float_Random.Reset(Self.PRNG, Random(G)); -- OPPONENT WIN COMMENTS -- Can I Play difficulty C := Self.List(Opponent_Win, Can_I_Play); Append (C, To_Unbounded_String ("You're too good for me")); Append (C, To_Unbounded_String ("How did you manage that?")); ... and so on. That works if I then finish with: Self.List(Opponent_Win, Can_I_Play) := C; But that's copy overhead I want to avoid (fifteen times, what's more). For the time being, I've just replaced all of the "C"s in the Append procedure calls with "Self.List(Opponent_Win, Can_I_Play)" (and variations thereof further down). How can I make "C" act like a reference to the Unbounded_String Vector? Also, is the 'To_Unbounded_String("this is a string")' really necessary? I thought I read in the ARM that string literals were defined for all the string types. Thanks, David P.S. Later on, I will probably read these comments from an XML file, but for now I'm just hard coding them into the program. -- David Trudgett http://www.zeta.org.au/~wpower/ FORTH IF HONK THEN