Mailinglist Archive: yast-devel (77 mails)

< Previous Next >
Re: [yast-devel] Is it allowed to modify one same list via foreach?
  • From: Arvin Schnell <aschnell@xxxxxxx>
  • Date: Wed, 2 Dec 2009 14:36:05 +0100
  • Message-id: <20091202133605.GA19079@xxxxxxx>
On Wed, Dec 02, 2009 at 02:22:06PM +0100, Johannes Meixner wrote:

Hello,

is such code allowed:
--------------------------------------------------------------------
list < string > words = [ "Jane", "John" ];
integer index = -1;
foreach( string word,
words,
{ index = index + 1;
words[index] = "Hello " + word;
}
);
--------------------------------------------------------------------
Is in any case the result words == [ "Hello Jane", "Hello John" ] ?

Use maplist:

words = maplist(string word, words, { return "Hello " + word; });

If it is not allowed, how to copy a list?
Does
--------------------------------------------------------------------
list < string > words = [ "Jane", "John", "Joe" ];
list < string > copy = words;
--------------------------------------------------------------------
result two totally separated lists words and copy
or does copy contain only a reference which points to words
so that
--------------------------------------------------------------------
remove( copy, 1 );
--------------------------------------------------------------------
would actually result copy == words == [ "Jane", "Joe" ] ?

No, a copy is made. AFAIR even in an efficient way using
reference counting.

ciao
Arvin

--
Arvin Schnell, <aschnell@xxxxxxx>
Senior Software Engineer, Research & Development
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG N├╝rnberg)
--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups
References