chharvey / counterpoint

A robust programming language.
GNU Affero General Public License v3.0
2 stars 0 forks source link

Syntax: Punning for Function Arguments #58

Open chharvey opened 3 years ago

chharvey commented 3 years ago

Dependent on #15, #24, and #57.

func myFunction(
    a: int,
    b: int = default_b,
    c: int = default_c,
    d: int = default_d,
    e: int = default_e,
): void => ();

let b: int = 42;
let c: int = 420;
let d: int = 4200;
let e: int = 42000;
let f: int = 24;
myFunction(
    42,
    b += f, % b= b + f
    c++,    % c += 1
    d= $,   % d= d
    e += $, % e += e;
)~~;
Label
-   ::= IDENTIFIER   "="                                           Expression;
+   ::= IDENTIFIER (("=" | AugmentOperator | AugmentNegate) ("$" | Expression) | UpdateOperator);
chharvey commented 3 years ago

Update: Only punning will be implemented, with a slight change in syntax. Augmentation will not be developed for arguments.

func scientist(firstname: str, lastname: str): str {
    return '''{{ firstname }} {{ lastname }}''';
}

let firstname: str = 'Albert';
let lastname:  str = 'Einstein';

scientist.(firstname= firstname, lastname= lastname);
scientist.(firstname$, lastname$);                    % equivalent to above

This completely supercedes the previous.

Syntax diff is equivalent to #24.