resizeable arrays: T[new]

Bill Baxter dnewsgroup at billbaxter.com
Mon Jun 4 04:40:04 PDT 2007


Daniel Keep wrote:
> I agree with your reasoning for this (honestly, the solution had never
> occured to me before, although looking back I can think of a few places
> where it would have been quite useful), although I can't say I'm a fan
> of the syntax.  The "new" inside the brackets just looks strange; a new
> what?
> 
> A few possible alternatives:
> 
> T[new]	// Proposed

Like the idea.  Not being able to tell a slice from a "real" array has 
always made me a bit uncomfortable, though it never occurred to me to 
make them separate types.  I would have expected it would introduce more 
headaches than it solves, but sounds like maybe not.  Cool.

T[new], though, doesn't speak to me as a syntax.

> T[$]	// Since $ already means "length" for arrays

Reminding us that '$'/length  can be assigned to ... not bad.

> T[..]	// Bit of a stretch...

I liked it at first till I realized it would mean the *opposite* of the 
what seems obvious to me -- i.e. I took it to mean that T is slice-like, 
meaning it can't be resized.  But it's supposed to be the other case.

> T[*]	// Indicating the index could be anything

That's not bad.

> T[volatile] // Bit long
Yeh, too long.

> T[[]]	// Just ugly
Eh.

Here's another:

T[~] // mnemonic: T can be concatenated onto

Or maybe it should just be a different brace type?
T{} = new T[10];

Probably breaks context freeness or something, but I like it if for no 
other reason than the braces are shift-[ shift-] on the US keyboard. 
It's also easy to type, and it's a nice mnemonic for array with 
augmented capabilities.

All the T[punctuation] varieties are going to be pretty annoying to 
type, I think.


--bb



More information about the Digitalmars-d-announce mailing list