View mode: basic / threaded / horizontal-split · Log in · Help
March 03, 2005
Re: $ instead of length
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?

Ugis
March 03, 2005
Re: $ instead of length
Hi..

Don't forget that 'length' always appears in kind-of the same form within
[ ]:

array[0..length-n]

(I don't know, can you reverse an array with array[length..0] ?)

Anyway, "#" seems a good candidate.

L.
March 03, 2005
Re: $ instead of length
Martin M. Pedersen wrote:
> "cahoots" <cahoots_member@pathlink.com> skrev i en meddelelse 
> news:d05p58$1bn6$1@digitaldaemon.com...
>  I do also. But it would conflict with CPP, as someone else pointed out.
> 
> I don't see any serious conflict with the preprocessor. First, '#' used 
> within the brackets is unlikely to appear as the first token on a line. 
> Second, an identifier is unlikely to appear as the following token. The only 
> place i see a potential conflict is within macro replacement lists, but i 
> could easily live with that.
> 
> Regards,
> Martin
> 
> 
I agree.  Anyhow, the "D preprocessor" is an imaginary thing that may 
not ever be needed.  I don't see why D should cater to a tool that 
doesn't exist.  If a preprocessor is required, it should conform to D, 
not the other way around.  I vote that # should be used to denote array 
length.

Brad
March 03, 2005
Re: $ instead of length
> The $ idea for the length is a good one. The reason I didn't adopt it was
> because I am trying to save $ for something big. I have a lot of thoughts
> (inspired by some emails from Andrei A.) that $ could be very, very useful
> in a future metaprogramming feature. Using $ as a length is a minor use, too
> minor for such an important symbol!
> 
> So the options are:
> 
> 1) Make it illegal for length within [ ] to hide another length in an outer
> scope. This would essentially preclude length being used as a global, or
> even as a class member.
> 
> 2) Same as (1), but only restrict it if length is a variable local to a
> function.
> 
> 3) Make length a keyword. This is not that much different from (1).
> 
> 4) Change length to another identifier. Nothing stands out as being
> obviously right.
> 
> 5) Invent a token for it that is other than '$'.

$len (or even $length) seems best to me, it doesn't conflict with 
anything and is markedly different than a normal identifier, as it 
should be. The only issue is backwards compatibility, but I guess the 
whole point is to change the current behavior, so that may not be a real 
issue? Perhaps it should be done together with (1) to not break all the 
code out there, just some..


xs0
March 03, 2005
Re: $ instead of length
Derek Parnell wrote:
> On Thu, 03 Mar 2005 10:57:34 +1300, brad@domain.invalid wrote:
> 
> 
>>Norbert Nemec wrote:
>>
>>>How about changing the identifier to 'len'?
>>>* Easy to read
>>>* Pretty intuitive to understand
>>>* I can't think of anything to mix it up with
>>>* used by other languages already (e.g. Python)
>>>* MUCH EASIER TO TYPE (Ever found yourself typeing "lenght"?)
>>>
>>>Question still is, how to handle it. The cleanest idea that I can come 
>>>with is to really make it a keyword. If you leave it an identifier, it 
>>>needs some special handling that makes the language more complex. One 
>>>more keyword does not hurt anyone. If it breaks any code, it will not do 
>>>it silently.
>>>
>>>My proposal would be to leave the property of arrays called "length". 
>>>Inside index espressions, it gives the length of the corresponding 
>>>dimension. (has to be worked out more clearly for ND-arrays) Anywhere 
>>>else it mich still serve as prefix operator, allowing to write 
>>>'len(myarray)' (or even 'len myarray') instead of myarray.length
>>
>>What about the ` (backtick) character, I don't think that we use that 
>>for anything right now.
>>
>>When used prefix to an array, it returns the length of the array, and 
>>when used inside [] it functions the same for the closest surrounding array.
>>
>>int[] i;
>>`i = 50; // set length
>>writef("Length is %d\n", `i);
>>i[`-1] = 0; // set last element in the array to 0
>>
>>Thoughts?
>>Brad
> 
> 
> The tick (back-quote) is already being used. It defines a raw string
> literal.
> 
>    char[] X = `c:\dmd\bin\`
> 
> However, the issue is that the syntax for slices and array references is 
> 
>  '[' Expression '..' Expression ']'
> 
> and
> 
>  '[' Expression ']'
> 
> respectively. So whatever is legal in an Expression is going to cause
> clashes and trouble for somebody at sometime. And even when you find an
> existing symbol/keyword that does not form a valid Expression, you can get
> the impression (eg. a 'lint' can form this idea) that the coder has just
> made a coding mistake. Thus things like Foo[4 .. - ] looks like the coder
> forgot something.
> 
> I also suggest that sticking to ASCII characters (for now) is going to
> cause less grief for all those millions of ASCII keyboards out there.
> 
> The $ symbol already denotes 'end of' in regular expressions, and many
> people are familiar with that. It is not a large context shift in people's
> current thinking. But if a lone $ is too important to 'waste' of this huge
> cost saving device (clarity and precision in referencing the end of an
> array), then maybe it can be combined to something else to form the
> required token. 
> 
>   len$ 
>   $$
>   [$] 
>   #$
>   $#
> 
> etc ... 
> 
> Some regard symbols as ugly, but I have the personal experience that a
> symbol to denote this concept truly aids the reading, *and* the writing, of
> code. This is not some theoretical belief.

We could always use ..$ which would't reserve $ (at least not that bad.

[foo .. ..$]
[2 .. ..$]

At this point one might even suggest a shorthand:
[2 ..$]
[2+3 .. ..$-7] or [2+3 ..$-7]
[0 .. (..$/2)]

I assume there's no problem with

anarray[lookuptable[3] .. lookuptable[..$]]

meaning from contents of index 3 of lokuptable to contents of the last 
index of lookuptable  -- are a slice of anarray?

It's not perfect, but it doesn't look fully ugly either. And the meaning 
of ..$ should be easy to figure out even without knowing D.
March 03, 2005
Re: $ instead of length
In article <d06rks$2e97$1@digitaldaemon.com>, xs0 says...
>
>> The $ idea for the length is a good one. The reason I didn't adopt it was
>> because I am trying to save $ for something big. I have a lot of thoughts
>> (inspired by some emails from Andrei A.) that $ could be very, very useful
>> in a future metaprogramming feature. Using $ as a length is a minor use, too
>> minor for such an important symbol!
>> 
>> So the options are:
>> 
>> 1) Make it illegal for length within [ ] to hide another length in an outer
>> scope. This would essentially preclude length being used as a global, or
>> even as a class member.
>> 
>> 2) Same as (1), but only restrict it if length is a variable local to a
>> function.
>> 
>> 3) Make length a keyword. This is not that much different from (1).
>> 
>> 4) Change length to another identifier. Nothing stands out as being
>> obviously right.
>> 
>> 5) Invent a token for it that is other than '$'.
>
>$len (or even $length) seems best to me, it doesn't conflict with 
>anything and is markedly different than a normal identifier, as it 
>should be. The only issue is backwards compatibility, but I guess the 
>whole point is to change the current behavior, so that may not be a real 
>issue? Perhaps it should be done together with (1) to not break all the 
>code out there, just some..
>
>
>xs0

I agree. And there's no issue with backward compatability since '$' is not legal
within an identifier.

As someone else noted, this should be extended to $arguments and $argptr -- it's
a good way to isolate meta-tags off to one side. Don't know what Walter has in
mind for '$' by itself, but surely it could be worked into a scheme of using '$'
as a tag prefix?

'#' is nice also, but it might be better to generalize the resolution to
something broader than just implicit array lengths?
March 03, 2005
Re: $ instead of length
> 4) Change length to another identifier. Nothing stands out as being
> obviously right.

final

and it would be length-1. So that one could write

 char[] x;
 ...
 x[final] = 0;
 x[ final .. final+1] = 0;

I don't think it is ambiguous with the use of final in other contexts, but I 
haven't completely checked that.
March 03, 2005
Re: $ instead of length
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
March 03, 2005
Re: $ instead of length
"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.
March 03, 2005
Re: $ instead of length
On Thu, 03 Mar 2005 11:20:40 -0800, John Reimer <brk_6502@yahoo.com> 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

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
1 2 3 4 5 6 7
Top | Discussion index | About this forum | D home