fubark / cyber

Fast and concurrent scripting.
https://cyberscript.dev
MIT License
1.16k stars 38 forks source link

Revising data literal syntax. #87

Closed fubark closed 4 months ago

fubark commented 5 months ago

I'm thinking of reverting to the previous {} and [] syntax for data literals. Although using [] for all data literals was a neat idea and unambiguous with indexing, it's easier to visually distinguish list data from record data if the delimiters are different.

It's also easier to visually separate an initializing type from the payload: T[a: 123] vs [T a: 123].

It get's worse if T is a generic expansion or an array-like type for eg: [[]T 1, 2, 3] Although it could be avoided with inference var a []T = [1, 2, 3], it's better to allow an idiomatic rhs initializer: var a = []T[1, 2, 3] This also means the empty record literal doesn't need special syntax. Previously [:], would change to {}.

Some other awkward cases with the current syntax: Record literal inside array literal: [[a: 123]] Declaring record members in multiple lines:

var b = [T
  a: 123,
  b: 234,
]
fubark commented 4 months ago

Resolved with c75689bfbbcc761d0b23ad33a854a15761ff2ccd