why $ is need to access array [negative index]?
Patrick Schluter
Patrick.Schluter at bbox.fr
Fri Sep 18 21:32:04 UTC 2020
On Friday, 18 September 2020 at 20:56:30 UTC, mw wrote:
> On Friday, 18 September 2020 at 20:48:47 UTC, bachmeier wrote:
>> I'm inclined to say typing a single character is not a
>> hardship in exchange for extreme clarity of the code. Keep in
>> mind that
>
> It not about saving "typing a single character".
>
> In the example I showed,
>
> signs[sign] = ...; // the sign can be -1, 0, 1
>
> in D, to write the same code, you have to test the sign and
> branch:
>
> if (sign >= 0) {
> signs[ sign] = ...;
> } else {
> signs[$+sign] = ...; // remember + here
> }
signs[1+sign]
More information about the Digitalmars-d
mailing list