Removal of implicit variable "length"
Bradley Smith
digitalmars-com at baysmith.com
Tue Jun 6 17:57:36 PDT 2006
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];
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.
Thanks,
Bradley
More information about the Digitalmars-d-learn
mailing list