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, <[email protected]>
Senior Software Engineer, Research & Development
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg)
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]