Skip to content

Commit 778342a

Browse files
committed
Change argument label syntax to use '=' instead of ':'
For consistency with other forms of value assignment. 'a: b' syntax is now purely for compile-time type constraints.
1 parent 403fe82 commit 778342a

33 files changed

+58
-53
lines changed

docs/book/functions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ void foo(public int b) {
4141
}
4242

4343
void main() {
44-
foo(a: 42); // prints "a"
45-
foo(b: 42); // prints "b"
44+
foo(a = 42); // prints "a"
45+
foo(b = 42); // prints "b"
4646
}
4747
```
4848

4949
Functions can return multiple values using tuples:
5050

5151
```cs
5252
(int a, bool b) foo() {
53-
return (a: 42, b: true);
53+
return (a = 42, b = true);
5454
}
5555

5656
void main() {

docs/book/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ active type of a union, etc. Should follow the "pay only for what you use" princ
247247

248248
__Named arguments__ as an optional way to avoid cryptic call sites like `foo(true, false)` by labeling the arguments with the corresponding
249249
parameter name, with the compiler checking that the argument labels match the parameter names, e.g.
250-
`foo(a: true, b: false)`. Consequently, named arguments don't have to be in same order as the parameters. This also
250+
`foo(verbose = true, ignoreErrors = false)`. Consequently, named arguments don't have to be in same order as the parameters. This also
251251
enables function overloading on parameter names.
252252

253253
__Defer statement__ to allow declaring arbitrary code, such as resource cleanup functions, to be executed when exiting the

docs/book/structs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ struct Person {
2525
}
2626

2727
void main() {
28-
var foo = Person(name: "Foo", age: 42, friend: null);
29-
var bar = Person(name: "Bar", age: 42, friend: foo);
28+
var foo = Person(name = "Foo", age = 42, friend = null);
29+
var bar = Person(name = "Bar", age = 42, friend = foo);
3030
foo.friend = bar;
3131

3232
foo.moveLeft(); // foo.x is now -0.1

examples/asteroids/missile.cx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ struct Missile {
3030
}
3131

3232
Vector2 tailPosition() {
33-
return (position - Vector2(missileSize, 0)).rotated(origin: position, angle: direction);
33+
return (position - Vector2(missileSize, 0)).rotated(origin = position, angle = direction);
3434
}
3535
}

examples/asteroids/player.cx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ struct Player {
2525
var b = Vector2(position.x - playerSize, position.y + playerSize);
2626
var c = Vector2(position.x + playerSize + playerSize, position.y);
2727

28-
a = a.rotated(origin: position, angle: direction);
29-
b = b.rotated(origin: position, angle: direction);
30-
c = c.rotated(origin: position, angle: direction);
28+
a = a.rotated(origin = position, angle = direction);
29+
b = b.rotated(origin = position, angle = direction);
30+
c = c.rotated(origin = position, angle = direction);
3131

3232
for (var i in -1...1) {
3333
for (var j in -1...1) {

examples/opengl/opengl.cx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int main()
4646
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
4747
if (infoLogLength > 0)
4848
{
49-
var infoLog = StringBuffer(uninitializedSize: infoLogLength + 1);
49+
var infoLog = StringBuffer(uninitializedSize = infoLogLength + 1);
5050
glGetProgramInfoLog(program, infoLogLength, null, infoLog.data());
5151
println(infoLog);
5252
}
@@ -100,7 +100,7 @@ void LoadShader(GLuint shaderID, string path)
100100
glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
101101
if (infoLogLength > 0)
102102
{
103-
var infoLog = StringBuffer(uninitializedSize: infoLogLength + 1);
103+
var infoLog = StringBuffer(uninitializedSize = infoLogLength + 1);
104104
glGetShaderInfoLog(shaderID, infoLogLength, null, infoLog.data());
105105
println(infoLog);
106106
}

src/parser/parse.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void Parser::parseStmtTerminator(const char* contextInfo) {
119119

120120
/// argument-list ::= '(' ')' | '(' nonempty-argument-list ')'
121121
/// nonempty-argument-list ::= argument | nonempty-argument-list ',' argument
122-
/// argument ::= (id ':')? expr
122+
/// argument ::= (id '=')? expr
123123
std::vector<NamedValue> Parser::parseArgumentList(bool allowEmpty) {
124124
parse(Token::LeftParen);
125125
std::vector<NamedValue> args;
@@ -132,7 +132,7 @@ std::vector<NamedValue> Parser::parseArgumentList(bool allowEmpty) {
132132
do {
133133
std::string name;
134134
Location location = Location();
135-
if (lookAhead(1) == Token::Colon) {
135+
if (lookAhead(1) == Token::Assignment) {
136136
auto result = parse(Token::Identifier);
137137
name = result.getString().str();
138138
location = result.getLocation();
@@ -275,7 +275,7 @@ ArrayLiteralExpr* Parser::parseArrayLiteral() {
275275

276276
/// tuple-literal ::= '(' tuple-literal-elements ')'
277277
/// tuple-literal-elements ::= tuple-literal-element | tuple-literal-elements ',' tuple-literal-element
278-
/// tuple-literal-element ::= (id ':')? expr
278+
/// tuple-literal-element ::= (id '=')? expr
279279
/// paren-expr ::= '(' expr ')'
280280
Expr* Parser::parseTupleLiteralOrParenExpr() {
281281
ASSERT(currentToken() == Token::LeftParen);
@@ -524,6 +524,7 @@ LambdaExpr* Parser::parseLambdaExpr() {
524524
return lambda;
525525
}
526526

527+
// TODO: change to: 'if' expr 'then' expr 'else' expr
527528
/// if-expr ::= expr '?' expr ':' expr
528529
IfExpr* Parser::parseIfExpr(Expr* condition) {
529530
ASSERT(currentToken() == Token::QuestionMark);

std/FileStream.cx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ struct OutputFileStream {
2424
}
2525

2626
OutputFileStream stdout() {
27-
return OutputFileStream(fileDescriptor: 1);
27+
return OutputFileStream(fileDescriptor = 1);
2828
}
2929

3030
OutputFileStream stderr() {
31-
return OutputFileStream(fileDescriptor: 2);
31+
return OutputFileStream(fileDescriptor = 2);
3232
}

std/List.cx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct List<Element> {
1818

1919
/// Initializes an list containing the elements of the given array.
2020
List(Element[] elements) {
21-
init(capacity: elements.size());
21+
init(capacity = elements.size());
2222

2323
// TODO: When array references can be iterated, iterate 'elements' directly.
2424
// TODO: Add push() overload for pushing all elements from an array reference.
@@ -99,7 +99,7 @@ struct List<Element> {
9999
/// Ensures that the capacity is large enough to store the given number of elements.
100100
void reserve(int minimumCapacity) {
101101
if (minimumCapacity > capacity) {
102-
var newBuffer = allocateArray<Element>(size: minimumCapacity);
102+
var newBuffer = allocateArray<Element>(size = minimumCapacity);
103103

104104
for (var index in 0..size) {
105105
var source = &buffer[index];
@@ -189,7 +189,7 @@ struct List<Element> {
189189
}
190190

191191
List<Output> map<Output>(Output(Element*) transform) {
192-
var output = List<Output>(capacity: this.size);
192+
var output = List<Output>(capacity = this.size);
193193

194194
for (var element in this) {
195195
output.push(transform(element));
@@ -199,7 +199,7 @@ struct List<Element> {
199199
}
200200

201201
List<Output> map<Output>(Output(Element) transform) {
202-
var output = List<Output>(capacity: this.size);
202+
var output = List<Output>(capacity = this.size);
203203

204204
for (var element in this) {
205205
output.push(transform(element));

std/StringBuffer.cx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct StringBuffer: Comparable, Hashable, Printable {
1414
}
1515

1616
StringBuffer(string s) {
17-
characters = List(capacity: s.size() + 1);
17+
characters = List(capacity = s.size() + 1);
1818

1919
for (var ch in s) {
2020
characters.push(ch);
@@ -40,7 +40,7 @@ struct StringBuffer: Comparable, Hashable, Printable {
4040

4141
/// Initializes the buffer to contain the given number of uninitialized bytes.
4242
StringBuffer(public int uninitializedSize) {
43-
characters = List(uninitializedSize: uninitializedSize + 1);
43+
characters = List(uninitializedSize = uninitializedSize + 1);
4444
characters[uninitializedSize] = '\0';
4545
}
4646

0 commit comments

Comments
 (0)