www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - $ instead of length

reply "Walter" <newshound digitalmars.com> writes:
[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 '$'.
Mar 02 2005
next sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Walter wrote:

 4) Change length to another identifier. Nothing stands out as being
 obviously right.
How about _length ? (Similar to the already used _arguments) --anders
Mar 02 2005
parent "Ben Hinkle" <bhinkle mathworks.com> writes:
"Anders F Björklund" <afb algonet.se> wrote in message 
news:d052rf$gbm$1 digitaldaemon.com...
 Walter wrote:

 4) Change length to another identifier. Nothing stands out as being
 obviously right.
How about _length ? (Similar to the already used _arguments) --anders
I like that. Some pluses and minuses: + indicates the identifier is special (prevents people from looking for a non-existant variable called "length") + precendent for using _identifier (as you mention) + is greppable - looks uglier than length - _length is more likely to be used in regular code than _arguments and _argptr Given that it isn't *that* much uglier I think the pluses outweight the minuses.
Mar 02 2005
prev sibling next sibling parent reply Georg Wrede <georg.wrede nospam.org> writes:
Walter 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. 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 a single-character token for length has worked well in Euphoria, where Rob incorporated it recently. The code gets a lot more readable, terse, and tends to decrease errors. I agree that one should not obstruct the way for Serious improvements to the laguage with frivolous introductions of minor things. Is there any single character other than $ that we could use? .... A throw-in-the-air idea, what if we used minus ("-")?
Mar 02 2005
next sibling parent "bamb00" <no email.com> writes:
Im totally for this , so speciying an offest from the end of an array would
look like


mySlice[0 .. -5];

I remember the argument against this being that its legal C to use a
negative offest for an array .  I can't imagine any noble purpose for it in
C/C++ , and I think it works perfect for the length property in D so lets
rally round the minus!

Charlie


"Georg Wrede" <georg.wrede nospam.org> wrote in message
news:42261AE9.2080708 nospam.org...
 Walter 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.

 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 a single-character token for length has worked well in Euphoria, where Rob incorporated it recently. The code gets a lot more readable, terse, and tends to decrease errors. I agree that one should not obstruct the way for Serious improvements to the laguage with frivolous introductions of minor things. Is there any single character other than $ that we could use? .... A throw-in-the-air idea, what if we used minus ("-")?
Mar 02 2005
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
"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]. :-(
Mar 02 2005
parent reply U.Baumanis <U.Baumanis_member pathlink.com> writes:
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
Mar 03 2005
next sibling parent reply "Walter" <newshound digitalmars.com> writes:
"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.
Mar 03 2005
next sibling parent reply Dave <Dave_member pathlink.com> writes:
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
Mar 03 2005
parent "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
"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! ;)
Mar 03 2005
prev sibling parent Ben Hinkle <Ben_member pathlink.com> writes:
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.
It isn't readable at all, though. It would look like someone pasted a chunk of Perl accidentally into some nice D code: z[$-1..$]=y[$-z[$-1]] I can't think of any other symbol in D that a C coder wouldn't be able to guess what it means.
Mar 03 2005
prev sibling parent Matthias Becker <Matthias_member pathlink.com> writes:
How about   for "something big" and $ for length?
Why does it need to be a single character? Couldn't it be e.g. <> ? To me <> looks a bit like something that means "length", or $ don't. -- Matthias Becker
Mar 04 2005
prev sibling next sibling parent Derek Parnell <derek psych.ward> writes:
On Wed, 2 Mar 2005 10:55:31 -0800, Walter 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. 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 '$'.
I'm still in the '$' camp. Since that symbol was introduced in Euphoria for this exact purpose, it has become an instant success and has literally changed the way one thinks about coding things. Using a word to do the same is always going to clash with something, sometime. -- Derek Parnell Melbourne, Australia http://www.dsource.org/projects/build 3/03/2005 7:22:15 AM
Mar 02 2005
prev sibling next sibling parent reply "Carlos Santander B." <csantander619 gmail.com> writes:
Walter 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. 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 '$'.
I think the only other ASCII symbol left not used in D is , but it looks kinda weird for length. Of course, Unicode is very vast... _______________________ Carlos Santander Bernal
Mar 02 2005
parent Georg Wrede <georg.wrede nospam.org> writes:
Carlos Santander B. wrote:
 Walter 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. 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 '$'.
I think the only other ASCII symbol left not used in D is , but it looks kinda weird for length. Of course, Unicode is very vast...
Shi-, er, baloney! That _does_ rise specters about us running up the creek with context independent lexing! What's gonna happen in two years?
Mar 02 2005
prev sibling next sibling parent reply Norbert Nemec <Norbert Nemec-online.de> writes:
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

Greetings,
Norbert



Walter schrieb:
 [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.
How about '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"?)
Mar 02 2005
parent reply brad domain.invalid writes:
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
Mar 02 2005
next sibling parent reply SeeSchloss <ng seeschloss.org> writes:
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
used somewhere ? Or what about '!', I don't think using it for length would conflict with the existing uses ? (same for ':') SeeSchloss
Mar 02 2005
parent reply brad domain.invalid writes:
 

 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 :) Brad
Mar 02 2005
parent "Carlos Santander B." <csantander619 gmail.com> writes:
brad domain.invalid wrote:
 

 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 :) Brad
There're #line And they're CPP directives, so should you run a preprocessor on your D code, it'd become a complete mess. (Sure, you'd say: we don't have or maybe even need a preprocessor, but even Walter has said you could always use one if badly needed. So, as _______________________ Carlos Santander Bernal
Mar 02 2005
prev sibling next sibling parent reply "Walter" <newshound digitalmars.com> writes:
<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.
Mar 02 2005
parent reply Matthias Becker <Matthias_member pathlink.com> writes:
 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.
Off-Topic: I thought you can't enter forward ticks on american keyboards at all? I thougth only ` and ' is avialble, not ´. Am I wrong? `'´`'´ -- Matthias Becker
Mar 04 2005
parent reply John Reimer <brk_6502 yahoo.com> writes:
On Fri, 04 Mar 2005 18:24:44 +0000, Matthias Becker wrote:

 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.
Off-Topic: I thought you can't enter forward ticks on american keyboards at all? I thougth only ` and ' is avialble, not ´. Am I wrong? `'´`'´ -- Matthias Becker
It's shares the same key as ~ on North American keyboards.``` -JJR
Mar 04 2005
parent John Reimer <brk_6502 yahoo.com> writes:
On Fri, 04 Mar 2005 04:05:13 -0800, John Reimer wrote:

 On Fri, 04 Mar 2005 18:24:44 +0000, Matthias Becker wrote:
 
 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.
Off-Topic: I thought you can't enter forward ticks on american keyboards at all? I thougth only ` and ' is avialble, not ´. Am I wrong? `'´`'´ -- Matthias Becker
It's shares the same key as ~ on North American keyboards.``` -JJR
Oops! I see your point... you seem to be correct. - JJR
Mar 04 2005
prev sibling parent reply Derek Parnell <derek psych.ward> writes:
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
Mar 02 2005
next sibling parent reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
 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.
I think that it make sense to use some generic approach for all builtin varables. Either declare all of them as keywords either use very distinct and uniform notation like: #arguments - var args #argptr Otherwise it is going to be a neverending story about name conflicts. BTW: char a[];
Mar 02 2005
parent Derek Parnell <derek psych.ward> writes:
On Wed, 2 Mar 2005 21:26:33 -0800, Andrew Fedoniouk wrote:

 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.
I think that it make sense to use some generic approach for all builtin varables. Either declare all of them as keywords either use very distinct and uniform notation like: #arguments - var args #argptr Otherwise it is going to be a neverending story about name conflicts. BTW: char a[];
Ok, I could live with that. Yeah, why not? It seems to work okay as a concept. -- Derek Parnell Melbourne, Australia http://www.dsource.org/projects/build/ 3/03/2005 5:00:01 PM
Mar 02 2005
prev sibling next sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Derek Parnell wrote:

What about the ` (backtick) character, I don't think that we use that 
for anything right now.
The tick (back-quote) is already being used. It defines a raw string literal. char[] X = `c:\dmd\bin\`
Yeah, and this is unfortunate enough since in both shell and Perl backticks mean escape and run a command - which is how I read it. Luckily I don't have any Windows paths here, so I'll just ignore it. And if I do need wysiwyg strings, I'll probably use the raw: r""... --anders
Mar 02 2005
prev sibling parent Georg Wrede <georg.wrede nospam.org> writes:
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.
Mar 03 2005
prev sibling next sibling parent reply "Ben Hinkle" <bhinkle mathworks.com> writes:
 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.
Mar 02 2005
parent "Walter" <newshound digitalmars.com> writes:
"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.
Mar 02 2005
prev sibling next sibling parent reply "Regan Heath" <regan netwin.co.nz> writes:
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
Mar 02 2005
parent reply "Walter" <newshound digitalmars.com> writes:
"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.
Mar 02 2005
parent reply Manfred Nowak <svv1999 hotmail.com> writes:
"Walter" <newshound digitalmars.com> wrote:

[...]
 Context free means you can parse it without looking up the
 identifiers in the symbol table.
[...] Do you mean this as a definition, or as an example for a grammar that is not context free? -manfred
Mar 04 2005
parent "Walter" <newshound digitalmars.com> writes:
"Manfred Nowak" <svv1999 hotmail.com> wrote in message
news:d0bbc5$2m4r$1 digitaldaemon.com...
 "Walter" <newshound digitalmars.com> wrote:

 [...]
 Context free means you can parse it without looking up the
 identifiers in the symbol table.
[...] Do you mean this as a definition, or as an example for a grammar that is not context free?
It's not a formal definition, but it's a practical one.
Mar 07 2005
prev sibling next sibling parent reply cahoots <cahoots_member pathlink.com> writes:
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 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?
Mar 02 2005
parent reply SeeSchloss <ng seeschloss.org> writes:
On Wed, 02 Mar 2005 23:26:10 +0000, cahoots wrote:

 In article <d052lp$h8q$1 digitaldaemon.com>, Walter says...
 
 
 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 use a compound symbol, such as [] to represent length?  X[0..[]] ?
with AltGr, but so are {} and [] anyway). '^' is also present, but not very practical since it's a dead key (so you have to type it twice, or type ^+space).
Mar 02 2005
parent reply cahoots <cahoots_member pathlink.com> writes:
In article <pan.2005.03.02.23.37.41.379145 seeschloss.org>, SeeSchloss says...
On Wed, 02 Mar 2005 23:26:10 +0000, cahoots wrote:

 In article <d052lp$h8q$1 digitaldaemon.com>, Walter says...
 
 
 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 use a compound symbol, such as [] to represent length?  X[0..[]] ?
with AltGr, but so are {} and [] anyway). '^' is also present, but not very practical since it's a dead key (so you have to type it twice, or type ^+space).
I do also. But it would conflict with CPP, as someone else pointed out. This kind of thing really seems to be the domain of meta-tags, since there's a bit of "implication" involved. I think it might be worth briefly exploring the general notion of meta-tags, and applying it to this case (e.g. $length, or length, and so on)
Mar 02 2005
parent reply "Martin M. Pedersen" <martin moeller-pedersen.dk> writes:
"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.


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
Mar 02 2005
parent reply brad beveridge <brad nowhere.com> writes:
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.
 

 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, length. Brad
Mar 03 2005
parent reply "Walter" <newshound digitalmars.com> writes:
"brad beveridge" <brad nowhere.com> wrote in message
news:d06ks2$2817$1 digitaldaemon.com...
 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,

 length.
There's no point to writing a D preprocessor. I just wanted to leave the door open for those folks who really, really, really want a preprocessor and so can use the standalone C preprocessor on it. The #line support in the language also makes it possible for any tool, not just the C preprocessor, to generate D code and yet have the error messages point properly back into the original non-D source. Tools like yacc and lex come to mind as working this way. P.S. The C preprocessor started out as just that, a text macro preprocessor that had nothing at all to do with C. It was a separate program entirely. If one carefully reads the preprocessor stuff in the C standard, it is still possible to make it a separate program. The preprocessor and C were combined into one compiler for performance, not semantic, reasons. Digital Mars includes a standalone C preprocessor, spp.exe, that could be used for D source. If one really, really, really wanted to <g>.
Mar 03 2005
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Walter wrote:

 P.S. The C preprocessor started out as just that, a text macro preprocessor
 that had nothing at all to do with C. It was a separate program entirely. If
 one carefully reads the preprocessor stuff in the C standard, it is still
 possible to make it a separate program. The preprocessor and C were combined
 into one compiler for performance, not semantic, reasons. Digital Mars
 includes a standalone C preprocessor, spp.exe, that could be used for D
 source. If one really, really, really wanted to <g>.
It's called "cpp" in GCC, by the way. Usually one uses "gcc -E", though. People have been using various forms of preprocessors for Java, too... Makes more sense there since Java does not have conditional compilation. I have been generating some of my more tedious D "ports", using Perl. :) Example: http://www.algonet.se/~afb/d/universalalphas/universalalphas.pl Generate: http://www.algonet.se/~afb/d/universalalphas/universalalphas.d So it's still kinda useful. Perhaps not as a language "feature", though? --anders
Mar 03 2005
prev sibling next sibling parent "Lynn Allan" <l_d_allan adelphia.net> writes:
 The $ idea for the length is a good one.
<alert comment="rude and uncalled for"> Interesting thread, but are the "fired neurons" expended on this thread getting us closer to 1.0? That's pretty harsh/tacky for me to say ... and I suppose it is relaxing and/or motivating for you to think about $ (on several levels :-) but the juxtaposition to the "Will D ever be ready?" thread brings out my flawed sarcastic tendencies. Mea culpa. Give me an F. What does it stand for? Focus. Give me another F. What does it stand for? Focus. I speak as a deeply unfocused person poking around unproductively at a lot of stuff that isn't getting finished. I suspect "The WB" is one of the most focused people on the face of this planet. </alert>
Mar 02 2005
prev sibling next sibling parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
"Walter" <newshound digitalmars.com> wrote in message 
news:d052lp$h8q$1 digitaldaemon.com...
 [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 '$'.
Here's a wacky idea: in an indexing expression [expr1] or [expr1 .. expr2] if the type of expr1 or expr2 is imaginary or complex then replace expr with (length - cast(int)expr.im + cast(int)expr.re) where expr is evaulated once. For example x[1i] equivalent to x[x.length-1] x[ k+m*1i .. n*1i ] equivalent to x[k+x.length-m .. x.length-n] Oh the fun we could have with complex arithmetic :-)
Mar 02 2005
parent "Walter" <newshound digitalmars.com> writes:
"Ben Hinkle" <ben.hinkle gmail.com> wrote in message
news:d05lv5$18ar$1 digitaldaemon.com...
 Oh the fun we could have with complex arithmetic :-)
Yes, if it doesn't work, rotate your code 90 degrees and try again.
Mar 02 2005
prev sibling next sibling parent "Lionello Lunesu" <lio lunesu.removethis.com> writes:
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] ?)



L.
Mar 03 2005
prev sibling next sibling parent reply xs0 <xs0 xs0.com> writes:
 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
Mar 03 2005
parent reply cahoots <cahoots_member pathlink.com> writes:
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? something broader than just implicit array lengths?
Mar 03 2005
parent reply pragma <pragma_member pathlink.com> writes:
In article <d07j1p$8s6$1 digitaldaemon.com>, cahoots says...

something broader than just implicit array lengths?
Thank you for your post... it really got me thinking. 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
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:

 void foobar(){


    mymatrix[0..#length
 }
- EricAnderton at yahoo
Mar 03 2005
parent "Nick Sabalausky" <z a.a> writes:
"pragma" <pragma_member pathlink.com> wrote in message 
news:d07vfo$2d2j$1 digitaldaemon.com...
 In article <d07j1p$8s6$1 digitaldaemon.com>, cahoots says...

something broader than just implicit array lengths?
Thank you for your post... it really got me thinking. 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
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:

 void foobar(){


 scopes
    mymatrix[0..#length
 }
- 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?
Mar 03 2005
prev sibling next sibling parent "Ben Hinkle" <bhinkle mathworks.com> writes:
 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.
Mar 03 2005
prev sibling next sibling parent reply John Reimer <brk_6502 yahoo.com> writes:
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: 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
Mar 03 2005
next sibling parent reply "Regan Heath" <regan netwin.co.nz> writes:
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:
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
Mar 03 2005
parent reply John Reimer <brk_6502 yahoo.com> writes:
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
Mar 03 2005
parent John Reimer <brk_6502 yahoo.com> writes:
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
Mar 03 2005
prev sibling parent reply Derek Parnell <derek psych.ward> writes:
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: 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
Mar 03 2005
parent reply John Reimer <brk_6502 yahoo.com> writes:
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: 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
Mar 03 2005
parent reply "Regan Heath" <regan netwin.co.nz> writes:
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: 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
Mar 03 2005
parent John Reimer <brk_6502 yahoo.com> writes:
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: 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
Mar 03 2005
prev sibling next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
 5) Invent a token for it that is other than '$'.
In that case, I'd suggest something untypable on most, if not all, computer keyboards. Perhaps the "top of integral sign" ? (ALT+244 in Windows) could mean "beginning of array," while "vertical line attached to two horizontal lines"? (ALT+213) could mean "end of array." Even better, if the ALT+numbers facility doesn't exist in other OSes, the characters will be completely inaccessible without the use of some kind of character map, or just copying and pasting. And with any luck, these characters will be different based upon character encodings and fonts. Or, we COULD just use "length."
Mar 03 2005
prev sibling parent reply Norbert Nemec <Norbert Nemec-online.de> writes:
Seems like my former post about this went unnoticed, since all three 
responses  seemed to completely ignore my words. Therefore again:

How about using 'len' as a keyword with the meaning of the currently 
proposed '$'?

It is much easier to type and not much longer than the '$'.

Also it spares the problem of wasting the character $ on such a profane 
purpose.

Finally, the word 'length' could still be used to define the routine, 
while 'len' could be an operator keyword. (Any existing code using len 
as local variable would break: not silently but with a 
unmisunderstandable error message.




Walter schrieb:
 [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 '$'.
Mar 05 2005
next sibling parent reply "Unknown W. Brackets" <unknown simplemachines.org> writes:
I've seen len used at least as often as length as a variable name...

-[Unknown]


 Seems like my former post about this went unnoticed, since all three 
 responses  seemed to completely ignore my words. Therefore again:
 
 How about using 'len' as a keyword with the meaning of the currently 
 proposed '$'?
 
 It is much easier to type and not much longer than the '$'.
 
 Also it spares the problem of wasting the character $ on such a profane 
 purpose.
 
 Finally, the word 'length' could still be used to define the routine, 
 while 'len' could be an operator keyword. (Any existing code using len 
 as local variable would break: not silently but with a 
 unmisunderstandable error message.
 
 
 
 
 Walter schrieb:
 
 [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 '$'.
Mar 05 2005
parent "Matthew" <admin.hat stlsoft.dot.org> writes:
"Unknown W. Brackets" <unknown simplemachines.org> wrote in message
news:d0e8od$2b1e$1 digitaldaemon.com...
 I've seen len used at least as often as length as a variable name...
That's far less important than the relative frequencies as property/method names. Nonetheless, I don't think 'len' is any more of a go-er than 'length'
 -[Unknown]


 Seems like my former post about this went unnoticed, since all three responses
 seemed to completely ignore my words. 
 Therefore again:

 How about using 'len' as a keyword with the meaning of the currently proposed
'$'?

 It is much easier to type and not much longer than the '$'.

 Also it spares the problem of wasting the character $ on such a profane
purpose.

 Finally, the word 'length' could still be used to define the routine, while
'len' could be an operator keyword. (Any 
 existing code using len as local variable would break: not silently but with a
unmisunderstandable error message.




 Walter schrieb:

 [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 '$'.
Mar 06 2005
prev sibling next sibling parent "Regan Heath" <regan netwin.co.nz> writes:
On Sat, 05 Mar 2005 15:24:27 +0100, Norbert Nemec  
<Norbert Nemec-online.de> wrote:
 Seems like my former post about this went unnoticed, since all three  
 responses  seemed to completely ignore my words. Therefore again:

 How about using 'len' as a keyword with the meaning of the currently  
 proposed '$'?

 It is much easier to type and not much longer than the '$'.

 Also it spares the problem of wasting the character $ on such a profane  
 purpose.

 Finally, the word 'length' could still be used to define the routine,  
 while 'len' could be an operator keyword. (Any existing code using len  
 as local variable would break: not silently but with a  
 unmisunderstandable error message.
I dislike it. I think 'len' is common, it would annoy me greatly to have to rename all my 'len' vars. I think any word solution suffers this problem of collision, as such any symbol solution is 'better'. Regan
 Walter schrieb:
 [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 '$'.
Mar 06 2005
prev sibling parent reply Derek Parnell <derek psych.ward> writes:
On Sat, 05 Mar 2005 15:24:27 +0100, Norbert Nemec wrote:

 Seems like my former post about this went unnoticed, since all three 
 responses  seemed to completely ignore my words. Therefore again:
 
 How about using 'len' as a keyword with the meaning of the currently 
 proposed '$'?
I guess that the probability of clashing with existing identifiers is higher than acceptable.
 It is much easier to type and not much longer than the '$'.
How about a 3-letter token that is not likely to clash? maybe 'qzz', or '_l_' or 'xyx', or ... ;-) Or maybe we could use a non-English word? Arabic or Chinese (Mandarin) might be good.
 Also it spares the problem of wasting the character $ on such a profane 
 purpose.
Yes, the $ should be used for currency literals ;-)
 Finally, the word 'length' could still be used to define the routine, 
 while 'len' could be an operator keyword. (Any existing code using len 
 as local variable would break: not silently but with a 
 unmisunderstandable error message.
Each new keyword placed into a language reduces the number of unique identifier names available for coders, thus to do so would have to have overwhelming benefit. I'm not yet convinced that 'len' as a keyword has that much benefit for us. -- Derek Melbourne, Australia 7/03/2005 11:07:42 AM
Mar 06 2005
parent =?UTF-8?B?QW5kZXJzIEYgQmrDtnJrbHVuZA==?= <afb algonet.se> writes:
Derek Parnell wrote:

Also it spares the problem of wasting the character $ on such a profane 
purpose.
Yes, the $ should be used for currency literals ;-)
I thought I would be using € for those shortly here, but we voted no. But I guess $ would work for the US/CA/AZ currency... Or for Perl :-) --anders
Mar 06 2005