A few simple syntactic proposals
Bill Baxter
dnewsgroup at billbaxter.com
Wed Apr 16 19:19:39 PDT 2008
Simen Kjaeraas wrote:
> On Thu, 17 Apr 2008 04:01:56 +0200, Jason House
> <jason.james.house at gmail.com> wrote:
>
>> Robert Fraser wrote:
>>> Also:
>>> Remove the implicit "length" inside slice brackets as it conflicts with
>>> outer length. Allow only $.
>>
>> Can you give an example of this?
>>
>> are you saying char[] foo = bar[3..length] should be replaced with char[]
>> foo = bar[3..$]? If yes, I don't see how the length is confusing. If
>> you're talking about nested indexing, I'd expect both length and $ to be
>> ambiguous.
>
>
> int length = 4;
> int[] foo;
>
> // ...
>
> auto bar = foo[0..length];
>
>
> will this slice from 0 to foo.length or 0 to 4?
The argument is that 'length' is a "stealth keyword".
It's not an official keyword, but you can't really use it for variable
names because they'll conflict with that implicit 'length' inside brackets.
Just using $ always for slicing solves that since $ is never a legal
variable name. Besides, do we really need two ways to do exactly the
same thing? I've never used "length" in indexing in D because I'm never
sure what it's going to do (many of my structs have a length property to
mimic built-in arrays -- if I say foo[0..length] in a method of that
struct which 'length' will it use?), and because $ is a lot less to type.
--bb
More information about the Digitalmars-d
mailing list