Array indexing and slicing

Luís Marques luismarques+spam at gmail.com
Mon Apr 3 15:47:37 PDT 2006


In article <e0s6a7$1sbs$1 at digitaldaemon.com>, Norbert Nemec says...
>b) The $ is even more powerful than Python-syntax in at least one very
>interesting way:
>	somearray[x%$,y%$,z%$]
>is the most beautiful solution I ever saw for the common problem of
>periodic boundaries!

Yes, that one is very nice.

>you mixed this up in your examples bringing in a -2 somewhere.

Thanks, I noticed it later.

>I call "omissive indices" only "[.." instead of "[0.." and "..]" instead
>of "..$]". Obviously these cover only the trivial corner cases and the
>syntax cannot naturally be extended to anything beyond these.

How would you extend it with $?

That's a good review. Things like this should be noted somewhere..

So,
$ is better designed for multidimensional arrays
$ is shorter than .length

Still thinking, then, couldn't this work:

somearray[x%length,y%length,z%length]

length would evaluate differently for each dimension of the array.
The only advantage would be $ being shorter (somearray[0..] would work for the
simpler cases)

Luís Marques



More information about the Digitalmars-d mailing list