DMD 0.177 release [Length in slice expressions]
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Wed Dec 20 13:23:28 PST 2006
Derek Parnell wrote:
> The concept was to have a very short symbol to represent the array's
> current element count. A number of different symbols were put forward, "#"
> being one of them. Walter rejected that one because it was already used for
> something else - the 'special token sequences' construct, such as "#line".
> Also symbols that consisted of identifier characters all have the same
> problem as "length" does. I favoured "$" because it was a single-character
> symbol and is already used in similar concepts inside regular expression
> syntaxes.
The "[..$]" syntax is also present in ColdC and its relatives (including my Bovis), so it
was familiar to me from the beginning. (That said I still harbor thoughts that $ could be
used for other things... but honestly, I think the syntax would be unambiguous: a lone $
as the right hand side of a slice expression should easily enough be distinguishable from
a $ anywhere followed by something, like an identifier.)
Which leads me to another thought. One other operator that ColdC and family posesses is
the @ for list splicing. Useless sample ColdC:
# var foo, bar, result;
#
# foo = {1, 2, 3};
# bar = {4, 5, 6};
# result = {@foo, @bar};
The 'result' variable now equals {1, 2, 3, 4, 5, 6}. Perhaps we could get something
similar in D, also using @, and then I think @ would possibly be a logical choice for
denoting "until end" in slices. I also think an 'opLength' operator is not a bad idea,
but it might be best just to require a .length property of some kind be present, since
presumably any class that exposes itself to slicing would likely also have a length
concept of some kind. (Contrary examples welcome.)
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-announce
mailing list