digitalmars.D - Synax of array slices.
- Andrew Fedoniouk (15/15) Nov 28 2005 Hi, gentlemen,
- Derek Parnell (10/25) Nov 28 2005 The double dots without a context can be harder to see than when they ha...
- Andrew Fedoniouk (7/18) Nov 28 2005 I am assuming that the most frequent use case is sort of
- Derek Parnell (23/47) Nov 28 2005 No it will not work because '$' its innermost scope is not a slice.
- Hasan Aljudy (4/69) Nov 28 2005 IMHO this corner case doesn't really show much, because if you ask me,
- Bruno Medeiros (6/11) Nov 29 2005 It works here. lastNonWS is just a regular function, right?
- Derek Parnell (8/16) Nov 29 2005 Well I am surprised. I just tried it to and it works. I don't know if th...
- F (10/35) Dec 03 2005 What about:
- Ben Hinkle (9/20) Dec 03 2005 MATLAB uses 'end' as well. In my experimental "Cx" language that I've be...
Hi, gentlemen, I've implemented in my script engine (close to ECMAScript) array slices (inspired by D, thanks). While doing this I came up with the idea of using four forms of slicing syntax: a[s..e] // standard, 's' and 'e' are as in D a[s..] // 'e' will be substituted by a.length a[..e] // 's' will be substituted by 0 a[..] // ... I am pretty sure this idea ($, a.length wars) was discussed already but cannot find it. Can you see any problems with this notation? If there is no major issues then probably makes sense to consider it in D? Andrew Fedoniouk. http://terrainformatica.com PS. TIScript lives on http://terrainformatica.com/tiscript/
Nov 28 2005
On Mon, 28 Nov 2005 16:19:51 -0800, Andrew Fedoniouk wrote:Hi, gentlemen, I've implemented in my script engine (close to ECMAScript) array slices (inspired by D, thanks). While doing this I came up with the idea of using four forms of slicing syntax: a[s..e] // standard, 's' and 'e' are as in D a[s..] // 'e' will be substituted by a.length a[..e] // 's' will be substituted by 0 a[..] // ... I am pretty sure this idea ($, a.length wars) was discussed already but cannot find it. Can you see any problems with this notation? If there is no major issues then probably makes sense to consider it in D?The double dots without a context can be harder to see than when they have a context. How is the idiom $-n meant to be shown? A incorrectly missing identifier is harder to detect as a mistake. -- Derek (skype: derek.j.parnell) Melbourne, Australia 29/11/2005 11:39:08 AM
Nov 28 2005
I am assuming that the most frequent use case is sort of a[n..] ( a[n..a.length] ) I beleive that in cases when you need a[ 0 .. $-n ] a[ 0 .. a.length - n ] will look better.a[s..e] // standard, 's' and 'e' are as in D a[s..] // 'e' will be substituted by a.length a[..e] // 's' will be substituted by 0 a[..] // ... Can you see any problems with this notation?The double dots without a context can be harder to see than when they have a context. How is the idiom $-n meant to be shown?A incorrectly missing identifier is harder to detect as a mistake.In complex cases $ is also not good too I beleive: a[0..lastNonWS($)] - will it work or not, btw? a[0..b[0..$].length] - what was ciphered here?
Nov 28 2005
On Mon, 28 Nov 2005 16:53:09 -0800, Andrew Fedoniouk wrote:And I believe the opposite ;-)I am assuming that the most frequent use case is sort of a[n..] ( a[n..a.length] ) I beleive that in cases when you need a[ 0 .. $-n ] a[ 0 .. a.length - n ] will look better.a[s..e] // standard, 's' and 'e' are as in D a[s..] // 'e' will be substituted by a.length a[..e] // 's' will be substituted by 0 a[..] // ... Can you see any problems with this notation?The double dots without a context can be harder to see than when they have a context. How is the idiom $-n meant to be shown?A incorrectly missing identifier is harder to detect as a mistake.In complex cases $ is also not good too I beleive:a[0..lastNonWS($)] - will it work or not, btw?No it will not work because '$' its innermost scope is not a slice.a[0..b[0..$].length] - what was ciphered here?The innermost scope of the '$' is the slice of the array 'b'. Therefore a slice of 'b' is taken from 0 to $ and then this length is used in the slice of 'a'. As you can see, this example uses a redundant format as a[0 .. b.length] would be sufficient. However a better example might have been ... a[m..b[n..$].length] which is alternatively written a[m..b[n..b.length].length] If we use more typical identifier names ... vCustomers[lStartPos..Sort.Bias[lUserChoice..Sort.Bias.length].length] and we start to see dots before our eyes ;-) Whereas vCustomers[lStartPos..Sort.Bias[lUserChoice..$].length] is reduced clutter, IMHO. -- Derek (skype: derek.j.parnell) Melbourne, Australia 29/11/2005 11:55:39 AM
Nov 28 2005
Derek Parnell wrote:On Mon, 28 Nov 2005 16:53:09 -0800, Andrew Fedoniouk wrote:IMHO this corner case doesn't really show much, because if you ask me, no one should code like that!! Wether you use $ or .length here doesn't make much differentce, it's confusing either way.And I believe the opposite ;-)I am assuming that the most frequent use case is sort of a[n..] ( a[n..a.length] ) I beleive that in cases when you need a[ 0 .. $-n ] a[ 0 .. a.length - n ] will look better.a[s..e] // standard, 's' and 'e' are as in D a[s..] // 'e' will be substituted by a.length a[..e] // 's' will be substituted by 0 a[..] // ... Can you see any problems with this notation?The double dots without a context can be harder to see than when they have a context. How is the idiom $-n meant to be shown?A incorrectly missing identifier is harder to detect as a mistake.In complex cases $ is also not good too I beleive:a[0..lastNonWS($)] - will it work or not, btw?No it will not work because '$' its innermost scope is not a slice.a[0..b[0..$].length] - what was ciphered here?The innermost scope of the '$' is the slice of the array 'b'. Therefore a slice of 'b' is taken from 0 to $ and then this length is used in the slice of 'a'. As you can see, this example uses a redundant format as a[0 .. b.length] would be sufficient. However a better example might have been ... a[m..b[n..$].length] which is alternatively written a[m..b[n..b.length].length] If we use more typical identifier names ... vCustomers[lStartPos..Sort.Bias[lUserChoice..Sort.Bias.length].length] and we start to see dots before our eyes ;-) Whereas vCustomers[lStartPos..Sort.Bias[lUserChoice..$].length] is reduced clutter, IMHO.
Nov 28 2005
Derek Parnell wrote:It works here. lastNonWS is just a regular function, right? -- Bruno Medeiros - CS/E student "Certain aspects of D are a pathway to many abilities some consider to be... unnatural."a[0..lastNonWS($)] - will it work or not, btw?No it will not work because '$' its innermost scope is not a slice.
Nov 29 2005
On Tue, 29 Nov 2005 11:16:30 +0000, Bruno Medeiros wrote:Derek Parnell wrote:Well I am surprised. I just tried it to and it works. I don't know if this is now a bug or not? Walter? -- Derek Parnell Melbourne, Australia 30/11/2005 1:42:42 AMIt works here. lastNonWS is just a regular function, right?a[0..lastNonWS($)] - will it work or not, btw?No it will not work because '$' its innermost scope is not a slice.
Nov 29 2005
What about: a[0..end]; //everything a[..]; //also everything a[k1..end-k2]; //a slice (redefining end here is not difficult, I think, is meaningfull, too) a[..,k1..end-k2,..]; //slicing over the second dim (end has the correspondent meaning) length of a will be end+1 then (no meaning outside []) Opinions? In article <4m61pv28t205$.1qh5v1k9041jy$.dlg 40tude.net>, Derek Parnell says...On Mon, 28 Nov 2005 16:19:51 -0800, Andrew Fedoniouk wrote:Hi, gentlemen, I've implemented in my script engine (close to ECMAScript) array slices (inspired by D, thanks). While doing this I came up with the idea of using four forms of slicing syntax: a[s..e] // standard, 's' and 'e' are as in D a[s..] // 'e' will be substituted by a.length a[..e] // 's' will be substituted by 0 a[..] // ... I am pretty sure this idea ($, a.length wars) was discussed already but cannot find it. Can you see any problems with this notation? If there is no major issues then probably makes sense to consider it in D?The double dots without a context can be harder to see than when they have a context. How is the idiom $-n meant to be shown? A incorrectly missing identifier is harder to detect as a mistake. -- Derek (skype: derek.j.parnell) Melbourne, Australia 29/11/2005 11:39:08 AM
Dec 03 2005
"F" <F_member pathlink.com> wrote in message news:dmsrfe$mhq$1 digitaldaemon.com...What about: a[0..end]; //everything a[..]; //also everything a[k1..end-k2]; //a slice (redefining end here is not difficult, I think, is meaningfull, too) a[..,k1..end-k2,..]; //slicing over the second dim (end has the correspondent meaning) length of a will be end+1 then (no meaning outside []) Opinions?MATLAB uses 'end' as well. In my experimental "Cx" language that I've been playing around with I chose 'end', too, with the following behavior: if the identifier 'end' is undefined in an indexing expression then it is replaced with the length. I don't remember if that's the same behavior as D's 'length'. I also took MATLAB's slicing syntax a:b instead of D's a..b. So in Cx to slice from position i to the end of x one would write x[i:end]. Maybe I'm just used to MATLAB but I find x[i:end] more readable than x[i..$].
Dec 03 2005