reduce string ranges

Jarrett Billingsley kb3ctd2 at yahoo.com
Mon Jun 16 18:09:24 PDT 2008


"Nick Sabalausky" <a at a.a> wrote in message 
news:g371nu$275q$1 at digitalmars.com...
>
> 1. Why does reduce need the seed to be manually specified anyway? Why not 
> just take the first element of the first range as the seed?

It could.  Some languages/libraries do.

> 2. If it did that, that still wouldn't solve the problem from the original 
> post, would it? I assume you'd need to do something weird like "auto 
> tstarr = ["one"[], "two"[], "three"[]];"?

You don't need to put the slice on every element, just the first.  That 
makes the compiler infer the type of the array literal as char[][] instead 
of char[3][].

> 3. I'm still getting my head around D2's strings so this'll probably sound 
> stupid, but why can't "" be implicitly converted to ""[]? (and how exactly 
> does that solve the original problem anyway)?

As said above, the compiler is too dumb to figure out that ["one", "two", 
"three"] is a char[][] and not a char[3][].  If string literals were dynamic 
arrays instead of fixed-size, we wouldn't need the [] at the end of the 
first element.

> BTW, ""[] means "a full start-to-end slice of the empty string literal", 
> right? Also, I know arrays and array slices are distict types, but what 
> exactly is the difference? My intuition would tell me that they're both a 
> pointer and a length, and an array slice is simply one that just happens 
> to point to a portion of another array, but lately I've been getting the 
> impression that there's something more to it than that?

No, they're not different types.  At least not yet.  Walter was throwing 
around the idea but it hasn't been implemented yet.  There is some ickiness 
with representing both as the same type.

Getting a full slice of a fixed-size array, such as a string literal, gives 
you a dynamic array reference.  Hence why it fixes the array literal. 





More information about the Digitalmars-d mailing list