why $ is need to access array [negative index]?
Steven Schveighoffer
schveiguy at gmail.com
Fri Sep 18 21:11:58 UTC 2020
On 9/18/20 4:56 PM, 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
> }
>
>
Well, if you don't care about verbosity.
signs[(sign + $) % $] = ...;
-Steve
More information about the Digitalmars-d
mailing list