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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2f1406ca802cdec5 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 08 Sep 2005 21:13:18 -0500 From: "Steve" Newsgroups: comp.lang.ada References: Subject: Re: Aliasing or referencing assignment Date: Thu, 8 Sep 2005 19:13:20 -0700 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: NNTP-Posting-Host: 24.22.63.157 X-Trace: sv3-xDduwGJqxaMySiXtAKjPYwvl+q65zEmDyjI961pgjmm3ya5E8+1/p8UMd6JjJL0a3Q1L2IErWYh2tQK!bnNxX1pykk8x5HHGImFuEWwMp3rQg1R4hr0eNJFQimi9iZEV+WIvryhLpcpcyilObzCgI1by+cOz!D4wKaxgMrZiGx195pP0njz8ORRA= X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:4542 Date: 2005-09-08T19:13:20-07:00 List-Id: "David Trudgett" wrote in message news:m3slwf3xcy.fsf@rr.trudgett... > > 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 > How about something like: declare C : ListElementType renames Self.List(Opponent_Win, Can_I_Play); begin ... code that uses C ... Append( C, To_Unbounded_String( "Blah blah" ) ); end; Steve (The Duck) > 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 >