Jump to page: 1 2 3
Thread overview
Just a thought with slices.
May 10, 2004
J Anderson
May 10, 2004
Norbert Nemec
May 10, 2004
J Anderson
May 10, 2004
Norbert Nemec
May 10, 2004
Kevin Bealer
May 10, 2004
Norbert Nemec
May 10, 2004
Ilya Minkov
May 10, 2004
J Anderson
May 10, 2004
J C Calvarese
May 11, 2004
A. Stevenson
May 11, 2004
Norbert Nemec
May 11, 2004
A. Stevenson
May 11, 2004
Norbert Nemec
May 11, 2004
J Anderson
May 11, 2004
Phill
May 11, 2004
A. Stevenson
May 11, 2004
J Anderson
May 11, 2004
A. Stevenson
May 10, 2004
Phill
May 11, 2004
J Anderson
May 11, 2004
Derek Parnell
May 11, 2004
Phill
May 10, 2004
Just a thought with slices.  What about if the namespaces became optional inside the square brackets (ie like a with statement).

ie
= test[0..length];

instead of:
= test[0..test.length];

Then you could also do negative versions like:

= test[0..length-10];

Since we use length in slices all the time, this would be handy syntax sugar.

This would also apply to UDT's.

-- 
-Anderson: http://badmama.com.au/~anderson/
May 10, 2004
I think the '$' idea is much simpler than that. Especially, if we have multidimensional arrays one day, where there is not only one length but several ranges for the individual dimensions.

(B.t.w: I chose the term "range" over "length" for multidimensional arrays, since it would seems strange to talk of several lengths instead of width, height or whatever. "length" should of course continue to for one-dimensional arrays as an alternative term)

        test[0..test.range[0]-1,0..test.range[1]]

would then become

        test[0..$-1,0..$-1]



J Anderson wrote:

> Just a thought with slices.  What about if the namespaces became optional inside the square brackets (ie like a with statement).
> 
> ie
> = test[0..length];
> 
> instead of:
> = test[0..test.length];
> 
> Then you could also do negative versions like:
> 
> = test[0..length-10];
> 
> Since we use length in slices all the time, this would be handy syntax sugar.
> 
> This would also apply to UDT's.


May 10, 2004
Norbert Nemec wrote:

>I think the '$' idea is much simpler than that. Especially, if we have
>multidimensional arrays one day, where there is not only one length but
>several ranges for the individual dimensions.
>
>(B.t.w: I chose the term "range" over "length" for multidimensional arrays,
>since it would seems strange to talk of several lengths instead of width,
>height or whatever. "length" should of course continue to for
>one-dimensional arrays as an alternative term)
>
>        test[0..test.range[0]-1,0..test.range[1]]
>
>would then become
>
>        test[0..$-1,0..$-1]
>  
>
New symbols are rarely good ways to make readable code (besides the common mathematical ones).  As soon as I see $, it's yet another symbol I have to go away and learn.  Besides with UDT's you would have access (without the dot) to any public member defined in that class not just length.

-- 
-Anderson: http://badmama.com.au/~anderson/
May 10, 2004
J Anderson wrote:

> Norbert Nemec wrote:
> 
>>I think the '$' idea is much simpler than that. Especially, if we have multidimensional arrays one day, where there is not only one length but several ranges for the individual dimensions.
>>
>>(B.t.w: I chose the term "range" over "length" for multidimensional arrays, since it would seems strange to talk of several lengths instead of width, height or whatever. "length" should of course continue to for one-dimensional arrays as an alternative term)
>>
>>        test[0..test.range[0]-1,0..test.range[1]]
>>
>>would then become
>>
>>        test[0..$-1,0..$-1]
>> 
>>
> New symbols are rarely good ways to make readable code (besides the common mathematical ones).  As soon as I see $, it's yet another symbol I have to go away and learn.

That's the same with every new language concept. And the meaning of $ is far easier to understand than the concept that inside of [] you are in a different namespace.

> Besides with UDT's you would have access
> (without the dot) to any public member defined in that class not just
> length.

True, but that might just as well be confusing, if the class defines members that you are not interested in, colliding with whatever you actually want to access. Besides: what other class members would you access so often in within brackets, that this would really make a big difference?

May 10, 2004
I like this.

-eye



J Anderson schrieb:

> Just a thought with slices.  What about if the namespaces became optional inside the square brackets (ie like a with statement).
> 
> ie
> = test[0..length];
> 
> instead of:
> = test[0..test.length];
> 
> Then you could also do negative versions like:
> 
> = test[0..length-10];
> 
> Since we use length in slices all the time, this would be handy syntax sugar.
> 
> This would also apply to UDT's.
> 
May 10, 2004
In article <c7o8n6$29p$1@digitaldaemon.com>, Norbert Nemec says... .
>> Besides with UDT's you would have access
>> (without the dot) to any public member defined in that class not just
>> length.
>
>True, but that might just as well be confusing, if the class defines members that you are not interested in, colliding with whatever you actually want to access. Besides: what other class members would you access so often in within brackets, that this would really make a big difference?
>

Regard this simple string class; regard this simple find method:

string has_waldo("micro-miniature waldo fabricator");
string wheres_waldo( has_waldo[find("waldo")..length] );

Kevin



May 10, 2004
J Anderson wrote:

> Just a thought with slices.  What about if the namespaces became optional inside the square brackets (ie like a with statement).
>
> ie
> = test[0..length];
>
> instead of:
> = test[0..test.length];
>
> Then you could also do negative versions like:
>
> = test[0..length-10];
>
> Since we use length in slices all the time, this would be handy syntax sugar.
>
> This would also apply to UDT's.
>
I should add.  It would also be useful for array indexes...

= test[length-1];



-- 
-Anderson: http://badmama.com.au/~anderson/
May 10, 2004
Kevin Bealer wrote:

> In article <c7o8n6$29p$1@digitaldaemon.com>, Norbert Nemec says... .
>>> Besides with UDT's you would have access
>>> (without the dot) to any public member defined in that class not just
>>> length.
>>
>>True, but that might just as well be confusing, if the class defines members that you are not interested in, colliding with whatever you actually want to access. Besides: what other class members would you access so often in within brackets, that this would really make a big difference?
>>
> 
> Regard this simple string class; regard this simple find method:
> 
> string has_waldo("micro-miniature waldo fabricator");
> string wheres_waldo( has_waldo[find("waldo")..length] );

OK, I have to yield to that. Personally, I still like the '$' concept, but that's probably just a matter of taste...
May 10, 2004
J Anderson wrote:
> Just a thought with slices.  What about if the namespaces became optional inside the square brackets (ie like a with statement).
> 
> ie
> = test[0..length];

That's a clever idea, but I'm afraid it'd lead to subtle errors. What if you meant test2.length? You won't get a compile error. If you're lucky, you'd get a runtime error. If you're unlucky, you'd just get the wrong result (and might not even realize it's the wrong result).

But using a symbol to represent this idea would be vastly "safer":
 = test[0..$length];
or
 = test[0..$];

My 2 cents.

> 
> instead of:
> = test[0..test.length];
> 
> Then you could also do negative versions like:
> 
> = test[0..length-10];
> 
> Since we use length in slices all the time, this would be handy syntax sugar.
> 
> This would also apply to UDT's.
> 


-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/
May 10, 2004
Im not with you, you can already do this:

 test[0..test.length - 10];



"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:c7npt6$2c59$1@digitaldaemon.com...
> Just a thought with slices.  What about if the namespaces became optional inside the square brackets (ie like a with statement).
>
> ie
> = test[0..length];
>
> instead of:
> = test[0..test.length];
>
> Then you could also do negative versions like:
>
> = test[0..length-10];
>
> Since we use length in slices all the time, this would be handy syntax sugar.
>
> This would also apply to UDT's.
>
> --
> -Anderson: http://badmama.com.au/~anderson/


« First   ‹ Prev
1 2 3