[DGD]Mappings with array indices

Erwin Harte harte at xs4all.nl
Sun Jan 21 19:10:27 CET 2001


On Sun, Jan 21, 2001 at 12:12:42PM -0500, Paul Belemjian wrote:
> I was trying to create some mappings that used arrays as their indices,
> and have met with some limited success.  The code I'm using to test it
> is below.  
> 
> void do_stuff()
> {
[...]
>     this_user()->message( foobar[bar] + "\n" );
>     this_user()->message( foobar[ ({ 0, 1 }) ] + "\n" );
> }
> 
> The results are this:  All of the statements in the for loop work and
> print out the correct results. 
> The second to last line also works and prints out the correct value.
> The last line doesn't work and returns an error (Value is not a string).
> 
> My question is if there is any way I can get the last line to work as
> written, without having to make a variable and assign the value to that
> first.

No.

If you do this:

  mixed *a, *b;

  a = ({ 0, 1 });
  b = ({ 0, 1 });

then a and b will be different arrays and in a comparison they will
not be considered equal, unlike for instance ints, floats and strings.

This also applies to an empty array by the way, so if you have an
if-statement like this:

  if (arr == ({ })) {
      ....
  }

then the code in the if-part of the statement will never be reached.

Depending on your application you'll have to work around this, I'm
afraid. :-)

Erwin.
-- 
Erwin Harte         :    `Don't mind Erwin, he gets crabby. :)'
harte at xs4all.nl     :       -- Par Winzell <zell at skotos.net>

List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list