From: David Trudgett <wpower@zeta.org.au.nospamplease>
Subject: Re: Aliasing or referencing assignment
Date: Fri, 09 Sep 2005 17:33:36 +1000
Date: 2005-09-09T17:33:36+10:00 [thread overview]
Message-ID: <m3psri8zlb.fsf@rr.trudgett> (raw)
In-Reply-To: xOadnZ2dnZ09ygbbnZ2dnSNyvd6dnZ2dRVn-0J2dnZ0@comcast.com
"Steve" <nospam_steved94@comcast.net> writes:
> "David Trudgett" <wpower@zeta.org.au.nospamplease> 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
next prev parent reply other threads:[~2005-09-09 7:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-09 0:20 Aliasing or referencing assignment David Trudgett
2005-09-09 2:13 ` Steve
2005-09-09 7:33 ` David Trudgett [this message]
2005-09-09 15:40 ` Jeffrey Carter
2005-09-10 7:38 ` David Trudgett
2005-09-10 10:01 ` Martin Dowie
2005-09-10 10:33 ` David Trudgett
2005-09-10 11:28 ` Ludovic Brenta
2005-09-11 20:43 ` David Trudgett
2005-09-11 3:20 ` Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox