With the coming of Nimony / Nim 3.0, would it be possible to include an option for tuple and object construction to use '=' instead of ':' ?
This, to me, is the one point where Nim is annoyingly inconsistent. '=' is used for assignment just about everywhere else, including procedure calls with named variables. (With Tables, the ':' has a better syntactic feel to me.) Yes, I do realize this is a petty request about syntactic style. No, I have no idea if this would break something in the parser.
Does anybody else think this is a good idea?
type
OStudent = object
name: string
age: int8
TStudent = tuple
name: string
age: int8
var o1 = OStudent(name: "Anton", age: 5)
var o2 = OStudent(name = "Victor", age=15)
var t1 = TStudent(name: "Anton", age: 5)
var t2 = TStudent(name = "Victor", age=15)
What's the point? Changing the fundamental syntax of a language without a REALLY good reason makes no sense. And even if there were a good reason, why? This decision would break literally everything. Let's say we make this syntax optional, then we'll end up in a situation like C++, where we have two syntaxes for creating objects, T() and T{}, but in our case there's no difference between them.
Speaking of inconsistency, why do you think this syntax is different from the rest of the language? When I see the syntax foo: bar, I consider it to be a new data construction, and foo = bar — a modification of existing data.
I kind of agree that it's inconsistent:
type MyType = object
foo, bar: int
proc initMyType(foo: int, bar: int): MyType = # ...
var a = MyType(foo: 1, bar: 2) # variable: value
var b = initMyType(foo = 1, bar = 2) # variable = value
# proposed syntax
var c = MyType(foo = 1, bar = 2)
If object constructors are parsed like function calls this should just be like default arguments. Although I'm not sure if it's possible/how easy it is to determine whether to parse as a function call or object constructor.
Although I'm not sure if it's possible/how easy it is to determine whether to parse as a function call or object constructor.
Why does object construction evhn need to be parsed differently? Just make the type act as the constructor when called as a function.