PDA

View Full Version : Comma operator, TStaticVar literals


Tolnaftate2004
12-20-2011, 02:46 AM
Comma operator
The associativity of the comma operator should be left-associative. The order of execution for its operands is reversed.

temp.a = 5, temp.b = temp.a;
Will not do what I'd expect. Instead, the operations have to be reversed to get the desired effect, which is confusing.

The same can be said of array literals and argument lists.

This is troublesome for when we have an iterator-type object (say it has a method called next):
temp.next_few_lines = { iter.next(), iter.next(), iter.next(), iter.next() };
and then the values are out of order.

TStaticVar literals
The notation I'm proposing would come straight from C:
{
.foo = "bar",
.baz = "qux",
.lumberjack = {
.spam = "eggs",
.knights = "ni",
.care = function () { return false; }
}
}

This would be useful for creating functions with a variable number of (named) arguments.

Consider then the code to add default values:
function extend(a,b) { // shared.extend, one day...
temp.dvnb = b.getdynamicvarnames();
temp.dvna = a.getdynamicvarnames();
for (temp.v: temp.dvnb) {
if (b.(@ temp.v).objecttype() == "TStaticVar") {
if (a.(@ temp.v) == NULL)
a.(@ temp.v) = new TStaticVar();
extend(a.(@ temp.v), b.(@ temp.v));
} elseif (a.(@ temp.v) == NULL && ! (temp.v in temp.dvna)) {
a.(@ temp.v) = b.(@ temp.v);
}
}
}

function PlayMozart(input) {
extend(input, { .key = "G", .song = "Eine kleine Nachtmusik" });

switch(input.key) {
case "C#":
case "Db":
// ...
}
}

Now, isn't that pretty? :)

Gunderak
12-27-2011, 12:22 PM
No because I dont understand it, although the song is xD

Admins
12-30-2011, 02:19 AM
Will check the comma thing. The object creator via {} could be interesting, we are trying to make things more close to javascript so that would fill a gap.

WhiteDragon
12-30-2011, 04:26 AM
Will check the comma thing. The object creator via {} could be interesting, we are trying to make things more close to javascript so that would fill a gap.

Nice :)