Removal of implicit variable "length"
kris
foo at bar.com
Tue Jun 6 18:18:33 PDT 2006
Bradley Smith wrote:
> Jarrett Billingsley wrote:
>
>> Have you heard of $ ?
>>
>> bar = foo[0 .. $];
>
>
> I did notice the mention of "$" in the old newsgroup thread. However, I
> can't find any official documentation on it.
>
>
>> Additionally, try turning on warnings for your original code, and
>> you'll notice you get one.
>
>
> Thanks for pointing out the warnings. I wasn't aware of that warning.
> Because libraries often cause many warnings, I don't regularly have
> warning turned on.
>
>
>> How about things like
>>
>> int[] x = ALongClassName.AnotherClassName.aNonTrivialOperation()[1 .. $];
>>
>> It's certainly nice to have a shortcut in cases like this, when typing
>> out the original expression is not only prohibitively long, but could
>> possibly waste performance re-evaluating the reference to the array.
>
>
> Why not the following?
>
> int[] ref = ALongClassName.AnotherClassName.aNonTrivialOperation();
> int[] x = ref[1 .. ref.length];
>
> Or perhaps?
>
> int[] x = ALongClassName.AnotherClassName.aNonTrivialOperation();
> x = x[1 .. x.length];
The original reason, IIRC, was with regard to using arrays + templates,
where it's not always so easy to leverage temps. However, that orignal
change brought us the maligned x[0..length] and its special cases. Took
a long time (a year, perhaps?) and many frustrating battles to get that
issue rectified, and the result was that sole '$' token
>
> Will use of "$" be faster than using a local reference?
>
> Unless there is a reason not to create a local reference to an array, I
> don't think either "length" or "$" are necessary. At least "$" shouldn't
> cause programming errors, but it does make the language more complex.
It was argued at the time that $len should be used, so that the $ prefix
could thus signify meta-notions in general ($file, $line, $time, etc).
In fact, it was perhaps the only time I recall a general concensus on
anything ;)
But, that notion went nowhere as you can see. We just move on
More information about the Digitalmars-d-learn
mailing list