Thread overview
Access original data from array
Oct 01, 2009
Moritz Warning
Oct 01, 2009
Tom S
Re: Access original data from array [OT]
Oct 01, 2009
Tom S
Oct 01, 2009
Moritz Warning
October 01, 2009
Hi,

how can I access the original value for xs?

I assume that xs is allocated at program start,
because I don't get an access violation on gnu/linux
when I reassign values.

But how can I access the original value?
Do I have to keep a copy before xs is modified?

import tango.io.Stdout;


void main(char[][] args)
{
    static char[][2] xs = ["abc", "123"];
    xs[0] = "foo";
    xs[1] = "bar";

    foreach(x; xs)
    {
        Stdout(x).newline;
    }

    //how to print "abc" "123" now?
}
October 01, 2009
Moritz Warning wrote:
> Hi,
> 
> how can I access the original value for xs?
> 
> I assume that xs is allocated at program start,
> because I don't get an access violation on gnu/linux
> when I reassign values.
> 
> But how can I access the original value?
> Do I have to keep a copy before xs is modified?
> 
> import tango.io.Stdout;
> 
> 
> void main(char[][] args)
> {
>     static char[][2] xs = ["abc", "123"];
>     xs[0] = "foo";
>     xs[1] = "bar";
>         foreach(x; xs)
>     {
>         Stdout(x).newline;
>     }
> 
>     //how to print "abc" "123" now?
> }

You were probably looking for the old meaning of .init, but it's gone now, so I present these alternative fixes:

1) You need to load the state of the game from before overriding xs. I recommend Quick Save and Quick Load. Often bound to F5 and F9.

2) Perhaps a custom-fit Delorian will do.

3) If all else fails, I'm afraid you'll have to resort to copying the contents of xs prior to overwriting them.


-- 
Tomasz Stachowiak
http://h3.team0xf.com/
h3/h3r3tic on #D freenode
October 01, 2009
Tom S wrote:
> 2) Perhaps a custom-fit Delorian will do.

DeLorean, even.
October 01, 2009
On Thu, 01 Oct 2009 05:02:10 +0100, Tom S wrote:

> Moritz Warning wrote:
>> Hi,
>> 
>> how can I access the original value for xs?
[..]
> 
> You were probably looking for the old meaning of .init, but it's gone now, so I present these alternative fixes:
> 
> 1) You need to load the state of the game from before overriding xs. I recommend Quick Save and Quick Load. Often bound to F5 and F9.
I tried F5 and F9, but I only accidently activated the bonus level. Quirky game...

> 2) Perhaps a custom-fit Delorian will do.
- A FluxCapacitator would be an overkill solution.
- I don't do coding while driving at > 88Mph.

> 
> 3) If all else fails, I'm afraid you'll have to resort to copying the contents of xs prior to overwriting them.
I will give it a try.

Thanks!