What's left before we can have array literals?

Stewart Gordon smjg_1998 at yahoo.com
Tue Sep 5 16:31:44 PDT 2006


This isn't yet another request for array literals to be implemented by 
the time 1.0 comes along, 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]

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?  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?

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- 
PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.



More information about the Digitalmars-d mailing list