== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
> Currently, D supports the special symbol $ to mean the end of a
> container/range.
> However, there is no analogous symbol to mean "beginning of a
> container/range".  For arrays, there is none necessary, 0 is always the
> first element.  But not all containers are arrays.
> I'm running into a dilemma for dcollections, I have found a way to make
> all containers support fast slicing (basically by imposing some
> limitations), and I would like to support *both* beginning and end symbols.
> Currently, you can slice something in dcollections via:
> coll[coll.begin..coll.end];
> I could replace that end with $, but what can I replace coll.begin with?
> 0 doesn't make sense for things like linked lists, maps, sets, basically
> anything that's not an array.
> One thing that's nice about opDollar is I can make it return coll.end, so
> I control the type.  With 0, I have no choice, I must take a uint, which
> means I have to check to make sure it's always zero, and throw an
> exception otherwise.
> Would it make sense to have an equivalent symbol for the beginning of a
> container/range?
> In regex, ^ matches beginning of the line, $ matches end of the line --
> would there be any parsing ambiguity there?  I know ^ is a binary op, and
> $ means nothing anywhere else, so the two are not exactly equivalent.  I'm
> not very experienced on parsing ambiguities, but things like ~ can be
> unambiguous as binary and unary ops, so maybe it is possible.
> So how does this look:  coll[^..$];
> Thoughts? other ideas?
> -Steve

I like it, if only for its happy aesthetic properties.

Reply via email to