March 03, 2005
Regan Heath wrote:
> 
> The last example looks a bit odd.. also is it legal to say:
> 
> y[-5 .. -1]  //slice the data before the start of the array
> 
> assuming you know there is data there?
> 
> Regan

No.  As is currently the case in D, I've made the assumption you cannot do a negative indexes.

The previous example: [0..] assumes that an "absent symbol" means "end of the array" or "length-1".  Thus [0..-1] is equivalent to "length-2".  This assumption can be made safely because there is no such thing as negative array indexing in D.

If negative array indexing did exist, then yes, this idea would make things quite confusing and would not be a good idea!

- JJR
March 03, 2005
John Reimer wrote:
> Regan Heath wrote:
> 
>>
>> The last example looks a bit odd.. also is it legal to say:
>>
>> y[-5 .. -1]  //slice the data before the start of the array
>>
>> assuming you know there is data there?
>>
>> Regan
> 
> 
> No.  As is currently the case in D, I've made the assumption you cannot do a negative indexes.
> 
> The previous example: [0..] assumes that an "absent symbol" means "end of the array" or "length-1".  Thus [0..-1] is equivalent to "length-2".  This assumption can be made safely because there is no such thing as negative array indexing in D.
> 
> If negative array indexing did exist, then yes, this idea would make things quite confusing and would not be a good idea!
> 
> - JJR

I'll admit, though, that having a negative number as the end-slice notation makes things "look" somewhat non-intuitive.  But sure can't be beat for brevity. :-P
March 03, 2005
On Thu, 03 Mar 2005 11:20:40 -0800, John Reimer wrote:

> Walter wrote:
>> 5) Invent a token for it that is other than '$'.
>> 
>> 
> 
> I'm not sure if anyone suggested it yet.  I'm sure it has been suggested in the past.  Why don't we use /no/ symbol:
> 
> # char[] y;
> # y[0 ..] = 0;   // slice from 0 to end of array - initialize to zero
> # y[..] = 0;     // slice equivalent to whole array (as above)
> # y[1 .. -1] = 0;	// slice from 1 to end of array-1
> 
> Perhaps I've completely missed some problem with this.  But it seems okay.
> 
> I don't too much like those methods that use a keyword or "length" symbol.  If feels awkward.
> 
> -JJR

Consider ...

  X = Y[];

Is this a coding error of omission, or am I choosing to capture the last character in Y, or am I selecting the entire Y array? I refer you to the D documentation (http://www.digitalmars.com/d/arrays.html) ...

"The [] is shorthand for a slice of the entire array."

-- 
Derek Parnell
Melbourne, Australia
4/03/2005 7:57:45 AM
March 03, 2005
Derek Parnell wrote:
> On Thu, 03 Mar 2005 11:20:40 -0800, John Reimer wrote:
> 
> 
>>Walter wrote:
>>
>>>5) Invent a token for it that is other than '$'.
>>>
>>>
>>
>>I'm not sure if anyone suggested it yet.  I'm sure it has been suggested in the past.  Why don't we use /no/ symbol:
>>
>># char[] y;
>># y[0 ..] = 0;   // slice from 0 to end of array - initialize to zero
>># y[..] = 0;     // slice equivalent to whole array (as above)
>># y[1 .. -1] = 0;	// slice from 1 to end of array-1
>>
>>Perhaps I've completely missed some problem with this.  But it seems okay.
>>
>>I don't too much like those methods that use a keyword or "length" symbol.  If feels awkward.
>>
>>-JJR
> 
> 
> Consider ...
> 
>   X = Y[];


It's as documented.


> Is this a coding error of omission, or am I choosing to capture the last
> character in Y, or am I selecting the entire Y array? I refer you to the D
> documentation (http://www.digitalmars.com/d/arrays.html) ...
> 
> "The [] is shorthand for a slice of the entire array."
> 

Yes, I looked at that.  Perhaps y[..] should be eliminated in my example or redefined to mean the last index in the array, ie. in a 10 index array, the slice: y[9..9].  Opinions welcome.

- JJR
March 03, 2005
In article <d07j1p$8s6$1@digitaldaemon.com>, cahoots says...
>
>'#' is nice also, but it might be better to generalize the resolution to something broader than just implicit array lengths?
>
Thank you for your post... it really got me thinking.


How about adding '#' (or '$' for that matter) as a 'present scope alias' for the
language overall?


Here's my rationale as applied to arrays:

An area inside a slice expression has already been morphed into something akin to a 'with' statement, with regards to the affected array via 'length'.  Since this occludes 'length' declarations in the parent scope, we need a way to access the current array without spelling out its entire name.

> // grab the last five elements of the array
> myarray[myarray.length-5 .. myarray.length]; // old (formal and hard to read)
> myarray[length-5 .. length]; // current (improved yet broken)
> myarray[#length-5 .. #length];  // suggested (# = 'myarray.')

In this case, using '#' as a scope alias solves the, well, "length of length expressions" problem *and* the scope hiding problem at the same time.


With respect to other parts of the language, it could be used in a similar fashion as to represent 'the current object/pointer type'.  I'm not sure how useful it would be in other contexts (generic programming perhaps?).  Some thought-provoking suggestions:


> myfunc(1,2,#); // '#' represents the current function/delegate pointer
> void foobar(){
>    function() thisfunc = #;  // get the current function as a pointer
>    if(this == ##); // do we allow multiple symbols to represent outer scopes
>    mymatrix[0..#length][0..##length]; // '##' == first array dimension.
> }


- EricAnderton at yahoo
March 03, 2005
On Thu, 03 Mar 2005 13:10:53 -0800, John Reimer <brk_6502@yahoo.com> wrote:
> Derek Parnell wrote:
>> On Thu, 03 Mar 2005 11:20:40 -0800, John Reimer wrote:
>>
>>> Walter wrote:
>>>
>>>> 5) Invent a token for it that is other than '$'.
>>>>
>>>>
>>>
>>> I'm not sure if anyone suggested it yet.  I'm sure it has been suggested in the past.  Why don't we use /no/ symbol:
>>>
>>> # char[] y;
>>> # y[0 ..] = 0;   // slice from 0 to end of array - initialize to zero
>>> # y[..] = 0;     // slice equivalent to whole array (as above)
>>> # y[1 .. -1] = 0;	// slice from 1 to end of array-1
>>>
>>> Perhaps I've completely missed some problem with this.  But it seems okay.
>>>
>>> I don't too much like those methods that use a keyword or "length" symbol.  If feels awkward.
>>>
>>> -JJR
>>   Consider ...
>>    X = Y[];
>
>
> It's as documented.
>
>
>> Is this a coding error of omission, or am I choosing to capture the last
>> character in Y, or am I selecting the entire Y array? I refer you to the D
>> documentation (http://www.digitalmars.com/d/arrays.html) ...
>>  "The [] is shorthand for a slice of the entire array."
>>
>
> Yes, I looked at that.  Perhaps y[..] should be eliminated in my example

I think it's ok if y[..] and y[] mean the same thing.
I assumed omitting the start index meant "from the start", not "from the end".

> or redefined to mean the last index in the array, ie. in a 10 index array, the slice: y[9..9].

That would be contrary to my initial assumption, maybe I'm weird.

Regan
March 03, 2005
Regan Heath wrote:
> On Thu, 03 Mar 2005 13:10:53 -0800, John Reimer <brk_6502@yahoo.com> wrote:
> 
>> Derek Parnell wrote:
>>
>>> On Thu, 03 Mar 2005 11:20:40 -0800, John Reimer wrote:
>>>
>>>> Walter wrote:
>>>>
>>>>> 5) Invent a token for it that is other than '$'.
>>>>>
>>>>>
>>>>
>>>> I'm not sure if anyone suggested it yet.  I'm sure it has been  suggested in the past.  Why don't we use /no/ symbol:
>>>>
>>>> # char[] y;
>>>> # y[0 ..] = 0;   // slice from 0 to end of array - initialize to zero
>>>> # y[..] = 0;     // slice equivalent to whole array (as above)
>>>> # y[1 .. -1] = 0;    // slice from 1 to end of array-1
>>>>
>>>> Perhaps I've completely missed some problem with this.  But it seems  okay.
>>>>
>>>> I don't too much like those methods that use a keyword or "length"  symbol.  If feels awkward.
>>>>
>>>> -JJR
>>>
>>>   Consider ...
>>>    X = Y[];
>>
>>
>>
>> It's as documented.
>>
>>
>>> Is this a coding error of omission, or am I choosing to capture the last
>>> character in Y, or am I selecting the entire Y array? I refer you to  the D
>>> documentation (http://www.digitalmars.com/d/arrays.html) ...
>>>  "The [] is shorthand for a slice of the entire array."
>>>
>>
>> Yes, I looked at that.  Perhaps y[..] should be eliminated in my example
> 
> 
> I think it's ok if y[..] and y[] mean the same thing.
> I assumed omitting the start index meant "from the start", not "from the  end".

True.  I had also considered that as a possibility.  They could be considered equivalent.

> 
>> or redefined to mean the last index in the array, ie. in a 10 index  array, the slice: y[9..9].
> 
> 
> That would be contrary to my initial assumption, maybe I'm weird.
> 
> Regan

No. That's not weird. I just wasn't sure which would be more intuitive.  You are probably correct with you're initial assumption.

I considered the above as a possibility because the "empty end-index" notation might need to be consistent when applied to the start index (ie. meaning the end-index because it's blank).  What's intuitive for people can be hard to predict.  Consistency does not always mean it's intuitive.

- JJR
March 03, 2005
In article <d07p4g$fp4$1@digitaldaemon.com>, Walter says...
>
>
>"U.Baumanis" <U.Baumanis_member@pathlink.com> wrote in message news:d06gf7$231k$1@digitaldaemon.com...
>> In article <d05as5$qei$1@digitaldaemon.com>, Walter says...
>> >
>> >
>> >"Georg Wrede" <georg.wrede@nospam.org> wrote in message news:42261AE9.2080708@nospam.org...
>> >> A throw-in-the-air idea, what if we used minus ("-")?
>> >
>> >Because then array[length - 1] becomes array[- - 1].
>> >
>> > :-(
>> >
>> How about @ for "something big" and $ for length?
>
>That's what Matthew suggested. I'm leaning that way at this point.
>

Gets my vote, FWIW.

- Dave


March 03, 2005
"Dave" <Dave_member@pathlink.com> wrote in message news:d083hj$2ha4$1@digitaldaemon.com...
> In article <d07p4g$fp4$1@digitaldaemon.com>, Walter says...
>>
>>
>>"U.Baumanis" <U.Baumanis_member@pathlink.com> wrote in message news:d06gf7$231k$1@digitaldaemon.com...
>>> In article <d05as5$qei$1@digitaldaemon.com>, Walter says...
>>> >
>>> >
>>> >"Georg Wrede" <georg.wrede@nospam.org> wrote in message news:42261AE9.2080708@nospam.org...
>>> >> A throw-in-the-air idea, what if we used minus ("-")?
>>> >
>>> >Because then array[length - 1] becomes array[- - 1].
>>> >
>>> > :-(
>>> >
>>> How about @ for "something big" and $ for length?
>>
>>That's what Matthew suggested. I'm leaning that way at this point.
>>
>
> Gets my vote, FWIW.

When you agree with me, it's worth the world! ;)


March 03, 2005
"pragma" <pragma_member@pathlink.com> wrote in message news:d07vfo$2d2j$1@digitaldaemon.com...
> In article <d07j1p$8s6$1@digitaldaemon.com>, cahoots says...
>>
>>'#' is nice also, but it might be better to generalize the resolution to something broader than just implicit array lengths?
>>
> Thank you for your post... it really got me thinking.
>
>
> How about adding '#' (or '$' for that matter) as a 'present scope alias'
> for the
> language overall?
>
>
> Here's my rationale as applied to arrays:
>
> An area inside a slice expression has already been morphed into something
> akin
> to a 'with' statement, with regards to the affected array via 'length'.
> Since
> this occludes 'length' declarations in the parent scope, we need a way to
> access
> the current array without spelling out its entire name.
>
>> // grab the last five elements of the array
>> myarray[myarray.length-5 .. myarray.length]; // old (formal and hard to
>> read)
>> myarray[length-5 .. length]; // current (improved yet broken)
>> myarray[#length-5 .. #length];  // suggested (# = 'myarray.')
>
> In this case, using '#' as a scope alias solves the, well, "length of
> length
> expressions" problem *and* the scope hiding problem at the same time.
>
>
> With respect to other parts of the language, it could be used in a similar
> fashion as to represent 'the current object/pointer type'.  I'm not sure
> how
> useful it would be in other contexts (generic programming perhaps?).  Some
> thought-provoking suggestions:
>
>
>> myfunc(1,2,#); // '#' represents the current function/delegate pointer
>> void foobar(){
>>    function() thisfunc = #;  // get the current function as a pointer
>>    if(this == ##); // do we allow multiple symbols to represent outer
>> scopes
>>    mymatrix[0..#length][0..##length]; // '##' == first array dimension.
>> }
>
>
> - EricAnderton at yahoo

I like it, but since it's a form of implicit behavior, could it lead to bugs from the code silently doing something other than what was intended?