March 02, 2005
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
March 02, 2005
> 3) Make length a keyword. This is not that much different from (1).

Would this mean we can't use length as a variable, function or property name? A quick grep of minwin and mintl turns up about 30 uses mostly in gtk.d (a port of GTK's header declarations) and about 30 more in MinTL (which uses length as a container property to mimic arrays). I would very much like to be able to continue to use length as a property name for custom types.



March 02, 2005
On Wed, 2 Mar 2005 10:55:31 -0800, Walter <newshound@digitalmars.com> wrote:
> [Starting a new thread on this, because the original is old and wandered off
> topic too far]
>
> "Derek Parnell" <derek@psych.ward> wrote in message
> news:cu90r1$1e7t$1@digitaldaemon.com...
>> Agreed. I have always supported the use of a symbol rather than an English
>> word to represent the array's length property. I'm keen to promote the
>> readibilty of source code by humans, so an extra 'dot' seems counter
>> productive to that aim.
>
>
> 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.

Not necessarily. eg.

int length; //global

void main() {
  int i;
  i = array.length;
  .. array[5 .. i];     //legal
  .. array[5 .. length] //illegal
  .. array[5 .. .length] //?
}


> 2) Same as (1), but only restrict it if length is a variable local to a
> function.

This will cause less collisions, but leave some, possibly more confusing?


> 3) Make length a keyword. This is not that much different from (1).

It's easier to understand, and implement, but less flexible than 1.


> 4) Change length to another identifier. Nothing stands out as being
> obviously right.

I think any word i.e. length, _length, etc has the same weakness, it may possibly collide.
I don't think this is an option by itself, it needs to be combined with one of the above.


> 5) Invent a token for it that is other than '$'.

I like this best. Can we start by trying to think of some, and failing that, remove this as an option. The only available single character ascii token easily available on a US keyboard is @, right? What about \, can that work? What about some double character options?

Just to clarify, for me, and perhaps others, "Context Free" means you can't use | (for example) because you need to know what | means without having to examine the context eg the fact that it's inside an array [] or does/doesn't have a variable or constant preceeding it, right?

array[0..|]   //0 to end
array[0..a|b] //0 to a|b

requires context?

Regan
March 02, 2005
On Thu, 03 Mar 2005 10:57:34 +1300, brad wrote:

> Norbert Nemec wrote:
>
> 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

I find ` hard to see, but I still prefer the 5th option... is # already used somewhere ?

Or what about '!', I don't think using it for length would conflict with the existing uses ? (same for ':')

SeeSchloss
March 02, 2005
<brad@domain.invalid> wrote in message news:d05crk$t04$1@digitaldaemon.com...
> What about the ` (backtick) character, I don't think that we use that
> for anything right now.

I tried that once. On too many fonts, it is indistinguishable from a forward tick. It's unusuable.


March 02, 2005
"Ben Hinkle" <bhinkle@mathworks.com> wrote in message news:d05cvl$t6u$1@digitaldaemon.com...
> > 3) Make length a keyword. This is not that much different from (1).
>
> Would this mean we can't use length as a variable, function or property name? A quick grep of minwin and mintl turns up about 30 uses mostly in gtk.d (a port of GTK's header declarations) and about 30 more in MinTL (which uses length as a container property to mimic arrays). I would very much like to be able to continue to use length as a property name for
custom
> types.

I agree. length as a keyword won't work. Too much water under that bridge.


March 02, 2005
> 
> I find ` hard to see, but I still prefer the 5th option... is # already
> used somewhere ?
> 
> Or what about '!', I don't think using it for length would conflict with
> the existing uses ? (same for ':')
> 
> SeeSchloss

I actually like ` being hard to see because it is less intrusive :)
But # would work well too I think.

Brad
March 02, 2005
"Regan Heath" <regan@netwin.co.nz> wrote in message news:opsm07p4lk23k2f5@ally...
> Just to clarify, for me, and perhaps others, "Context Free" means you can't use | (for example) because you need to know what | means without having to examine the context eg the fact that it's inside an array [] or does/doesn't have a variable or constant preceeding it, right?
>
> array[0..|]   //0 to end
> array[0..a|b] //0 to a|b
>
> requires context?

Context free means you can parse it without looking up the identifiers in the symbol table. The above example you give is still parseable without doing semantic analysis, but it does add complexity to the grammar that is unfortunate. I'd rather have a token that is not overloaded with other meanings.


March 02, 2005
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.

-- 
Derek
Melbourne, Australia
3/03/2005 9:41:56 AM
March 02, 2005
In article <d052lp$h8q$1@digitaldaemon.com>, Walter says...
>
>[Starting a new thread on this, because the original is old and wandered off topic too far]
>
>"Derek Parnell" <derek@psych.ward> wrote in message news:cu90r1$1e7t$1@digitaldaemon.com...
>> Agreed. I have always supported the use of a symbol rather than an English word to represent the array's length property. I'm keen to promote the readibilty of source code by humans, so an extra 'dot' seems counter productive to that aim.
>
>
>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 '$'.
>
>

Using anything that might be used as a variable-name is problematic. Decorating the name (such as _length) makes a collision less likely, but then you'd still have to make it a reserved word.

Using a symbol instead seems like the right approach since a) it can never be
confused with user-space, and b) it doesn't extend the reserved-word list (it
can't be used within an identifier).

Perhaps # could be applied (if present on European keyboards) ? Perhaps '^'? Or perhaps use a compound symbol, such as [] to represent length?  X[0..[]] ?

How about somehow using .sizeof ?

If you were going to reserve $ for meta-programming, then you might consider using it as a 'prefix' for meta-tags (instead of standalone). If so, $len or $sizeof might work?


1 2 3 4 5 6 7
Top | Discussion index | About this forum | D home