What's left before we can have array literals?
Ivan Senji
ivan.senji_REMOVE_ at _THIS__gmail.com
Tue Sep 5 17:45:19 PDT 2006
Stewart Gordon wrote:
> This isn't yet another request for array literals to be implemented by
> the time 1.0 comes along,
:D
> just a look at how far away we really are.
>
> There are really two separate issues to it:
>
>
> 1. Deciding on a notation and writing the code to parse it
>
> A number of notations have been proposed. I personally like the
> notation proposed by Chris Miller (digitalmars.D:39125, "Proposal:
> struct and array literal syntax").
>
> Basically, it works like this:
>
> int[]![6, 7, 8, 9]
Yeah, this is really, really the best one so far.
>
> As I see it, what follows the '!' takes the form of an array initialiser
> - consequently, an array of arrays or structs can be created by
> embedding array or struct initialisers within the array literal. The
> only difference is that they might not have to be compile-time constants
> - but it would work considering that the types are known at compile time
> just the same.
>
>
> 2. Building the internal workings
>
> We already have string literals. Using the same internal workings for
> array literals would at least enable us to have array literals that are
> compile-time constants. Of course, to allow elements of array literals
> to be evaluated at runtime, the workings would have to be set up to
> support it.
>
> Walter recently wrote, of the possibility of lazy variadics:
>
> "What it means is an array literal is created out of the arguments,
> which is then wrapped in a delegate.
>
> That cannot work until array literals are implemented."
>
> But I'm rather puzzled by this claim. When you call a typesafe variadic
> function, even when it isn't lazy, is this not effectively an array
> literal, at least internally?
Hmm, I never thought about it that way but actually that is what it
really is. I mean that is what I have been using
T[] array(T)(T[] x...) for -> As an array literal.
So I have a strong feeling that array literals aren't that far away.
> If it is, then this would mean that we
> already have the workings towards supporting array literals, and could
> use them in lazy variadics just the same. Otherwise, how does it work
> at the moment?
Magic?
More information about the Digitalmars-d
mailing list