Choosing the perfect array/vector syntax… Vote in the comments!

In the Rae programming language arrays are going to be implemented using C++ std::vectors. And I’m also thinking of implementing static arrays as std::array, but I’d like them to have the same syntax, and be interchangeable in function arguments, so that requires some more thought…

But what would be the perfect syntax for arrays?

As a reminder you create normal variables like this:

val SomeClass someObject
link SomeClass link_to_ob -> someObject
opt SomeClass someOptObject -> null

So the approach is to use more words and less special characters. But I might want to change this approach as it comes to arrays…

Here’s how arrays are created in the related languages:

vector<Tester> testers; //C++
vector<Tester*> testers; //C++
vector!(Tester) testers; //D
Tester[] testers; //D
Tester testers[];
[Tester] testers //Swift and maybe some other languages...

And here are the candidates for Rae. Feel free to propose more.

array val Tester testers

arr val Tester testers

vec val Tester testers	

vec[val Tester] testers

vec(val Tester) testers
[val Tester] testers
val Tester[] testers

Vote for your favourite in the comments. 🙂

Somehow, even though otherwise we are using words, the words start to clutter things pretty fast. If we’d want a protected optional array which holds objects by value, we’d write:

protected opt vec val Tester testers

And that would pretty much hide the “vec” and the fact that we have an array. Syntax highlighting might help there, but it still would be hidden.

For some reason I really like brackets in array syntaxes. So currently I think this looks the best, and it neatly looks sort of like a template too:

[val Tester] testers

And it is easy to parse, because the first character in the line is a bracket, so we’re waiting for an array.

So, continuing that thought the [] would implicitly be

val vec[val Tester] testers
//and a link to an array would be:
link [val Tester] linkToArray

And templates would then implicitly be usually val, unless stated otherwise.
//A related note: template syntax with brackets?

vector[Tester] testers
signal[void, int, float] mouseClicked
//But signals deserve a better syntax.

But this “implicitly val” leads to the question, shouldn’t everything be implicitly val? Then we’d really be close to C++ like in our original example of Rae syntax:

SomeClass someObject
link SomeClass link_to_ob -> someObject
opt SomeClass someOptObject -> null

//And our array syntax for value array 
//with value types would be just like in Swift:
[Tester] testers

It is slightly more painfull to parse, as the joy of declaring everything with reserved words beforehand, makes parsing so easy. But maybe I could manage with this syntax…

Any thoughts? Any readers? 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s