Top 5

Sergey Gromov snake.scaly at gmail.com
Fri Oct 10 08:38:09 PDT 2008


Fri, 10 Oct 2008 09:33:43 -0500,
Andrei Alexandrescu wrote:
> Sergey Gromov wrote:
> > Fri, 10 Oct 2008 08:22:10 -0500,
> > Andrei Alexandrescu wrote:
> >> Sergey Gromov wrote:
> >>> My T[] is useful when you want to recursively split a megabyte file into 
> >>> a couple thousands of tokens, and then modify some of those tokens.  For 
> >>> that, your T[] must be lightweight, it must reference a bigger piece of 
> >>> data, and it must guarantee not to write anything into memory outside 
> >>> its boundaries.
> >>>
> >>> The Array is for appending.  It must always own its memory.  Therefore 
> >>> you should be able to pass it around by reference, so Array is a *class* 
> >>> and cannot be nearly as lightweight as T[].
> >>>
> >>> You see, many of their properties are orthogonal.  If you drop one, you 
> >>> lose flexibility.
> >>>
> >>>> Besides, Array!(T) is not a good name for build-in type.
> >>> Names are placeholders here, not an actual proposal.
> >> What's wrong with making Array a library type?
> > 
> > Well, I'd like
> >   new Object[15];
> > to be immediately appendable and therefore a syntactic sugar for 
> >   new Array!(Object)(15);
> 
> I have a nagging impression the syntax Array!(Object) strikes you as 
> hard on the hand and the eyes...

Yes you are right.  If I had to write "new AA!(int, string)" instead of 
simply "int[string]" I think I wouldn't even bother learning D.

> Anyhow the syntax new Object[15] is idiotic because Object[15] is a type 
> in itself. The syntax makes it next to impossible to actually generate a 
> fixed-sized array dynamically.
> 
> In fact here's a challenge for you. Please generate a pointer to an 
> Object[15] using new.

alias Object[15] Type;
pragma(msg, typeof(new Type).stringof);

> test.d(7): Error: new can only create structs, dynamic arrays or class objects, not Object[15u]'s
> Object[15u]*

:-D

> 
> > I'd also like
> >   "foo" ~ text ~ "bar"
> > to become something like
> >   (new Array!(char)) ~= "foo" ~= text ~= "bar"
> > that is what Java does to string concatenation.  Sugar doesn't seem to 
> > couple well with a purely library type.
> > 
> > Well, the latter is probably too complex and can cause major problems.  
> > But new T[] should return something appendable.
> 
> I'm not 100% sure about that.

I'm not sure either, in part because of implicit type juggling.



More information about the Digitalmars-d mailing list