std.xml should just go

Jonathan M Davis jmdavisProg at gmx.com
Sat Feb 12 05:48:30 PST 2011


On Saturday 12 February 2011 03:08:15 bearophile wrote:
> Jonathan M Davis:
> > Except that then you get the issue of eager vs lazy concatenation. chain
> > is lazy whereas ~ is eager, so that wouldn't fly.
> 
> In dlibs1 I have a lazy chain(). If you perform a chain(chain(x, y), z) or
> chain(x, chain(y, z)) it's rewritten as chain(x,y,z). Plus there's a
> "chainable" mixin. If you mix it into a struct or class, the struct or
> class defines the ~ and ~= operators, making them mean chain(). All this
> requires no changed in the compiler front-end, and I think it doesn't have
> the problem you mention.

It's a problem of semantics. ~ is intended for eager concatenation. That's how 
it's designed and what it's expected to mean. More importantly, that's how it 
works for arrays. If you made it lower to chain, then either ~ for arrays has 
become lazy (along with every other user-defined type which overloads 
opBinary!"~" and made it eager as would be expected), or it's eager for some 
stuff and non-eager for others, meaning that you can't rely on whether ~ is eager 
or not when you use it. Either case would be bad.

Yes, you _could_ make ~ lower to chain, but it changes the semantics just for 
some syntactic sugar. I think that that is a _bad_ idea.

Regardless, as it's not going to be implemented any time soon, there's not much 
point in debating it right now.

- Jonathan M Davis


More information about the Digitalmars-d mailing list