On Sat, 02 Jun 2012 07:49:16 -0400, Dario Schiavon
<[email protected]> wrote:
Hi,
I just read some old threads about opDollar and the wish to have it work
for non zero-based arrays, arrays with gaps, associative arrays with
non-numerical indices, and so on. It was suggested to define opDollar as
the end of the array rather than the length (and perhaps rename opDollar
to opEnd to reflect this interpretation), so that collection[someIndex
.. $] would consistently refer to a slice from someIndex to the end of
the collection (of course the keys must have a defined ordering for it
to make sense).
I'm just thinking, if we want to generalize slices for those cases,
shouldn't we have a symmetrical operator for the first element of the
array? Since the $ sign was evidently chosen to parallel the regexp
syntax, why don't we add ^ to refer to the first element? This way,
collection[^ .. $] would slice the entire collection, just like
collection[].
Until now, ^ is only used as a binary operator, so this addition
shouldn't lead to ambiguous syntax. It surely wouldn't be used as often
as the opDollar, so I understand if you oppose the idea, but it would at
least make the language a little more "complete".
I suggested this, and it was shot down rather pointedly by Walter (with
not very convincing arguments I might add). Probably not much chance of
success.
http://forum.dlang.org/post/[email protected]
-Steve