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 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!ucberkeley!newsfeed.pacific.net.au!nasal.pacific.net.au!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Aliasing or referencing assignment From: David Trudgett Organization: Very little? References: Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:oqSwFYWpomDJAVnMHSvU3Q8LvkM= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 09 Sep 2005 17:33:36 +1000 NNTP-Posting-Host: 61.8.45.184 X-Complaints-To: news@pacific.net.au X-Trace: nasal.pacific.net.au 1126251489 61.8.45.184 (Fri, 09 Sep 2005 17:38:09 EST) NNTP-Posting-Date: Fri, 09 Sep 2005 17:38:09 EST Xref: g2news1.google.com comp.lang.ada:4547 Date: 2005-09-09T17:33:36+10:00 List-Id: "Steve" writes: > "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; That's exactly what I needed, Steve! Thanks. I actually tried to use "renames", but I guess I must have got it slightly wrong. It's very handy to be able to declare variables of restricted scope like that in Ada, too! Like in Lisp (with LET and LET*), and unlike Pascal. Anyway, for the record, this is what worked: declare C : String_List.Container_Type renames Self.List(Game_Start, Nightmare); begin Append (C, To_Unbounded_String ("Go ahead, make my day...")); ... and so on end; Cheers, David -- David Trudgett http://www.zeta.org.au/~wpower/ "The high office of the President has been used to foment a plot to destroy the American's freedom and before I leave office, I must inform the Citizen of his plight." -- John F. Kennedy, speaking at Columbia University, 10 days before his assassination