Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Feature request (https://forums.graalonline.com/forums/forumdisplay.php?f=194)
-   -   Comma operator, TStaticVar literals (https://forums.graalonline.com/forums/showthread.php?t=134265333)

Tolnaftate2004 12-20-2011 02:46 AM

Comma operator, TStaticVar literals
 
Comma operator
The associativity of the comma operator should be left-associative. The order of execution for its operands is reversed.

PHP Code:

temp.5temp.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):
PHP Code:

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:
PHP Code:

{
  .
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:
PHP Code:

function extend(a,b) { // shared.extend, one day...
  
temp.dvnb b.getdynamicvarnames();
  
temp.dvna a.getdynamicvarnames();
  for (
temp.vtemp.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

Quote:

Originally Posted by Stefan (Post 1680008)
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 :)


All times are GMT +2. The time now is 07:51 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.