3 ms·
A small but (IMHO) very neat detail is the Pascal-style syntax for defining variables (without requiring a separate 'var' or 'let' keyword): // inferred ty
by flohofwoe 4y ago
A small but (IMHO) very neat detail is the Pascal-style syntax for defining variables (without requiring a separate 'var' or 'let' keyword):
// inferred type:
a := 23
// explicitly typed, the type is squeezed between the : and =
a : u32 = 23
OTH constants now require special syntax:
a :: 23
...but at least this is consistent with other places in the language, like functions:
my_func :: proc(...)
...and 'squeezing in the type' also works as expected for constants (which admittedly looks a bit weird, but is also hardly needed):
a : u32 : 23
- brabel 4y agoSo, the pattern is: <const_name> : [type] : <value> <var_name> : [type] = <value> where the type is always optional as it can be inferred? That's why `a :: 32` declares a constant, but `a := 32` declares a variable... This is pretty neat, actually.
- mananaysiempre 4y agoThis pun originates from Limbo, I think. Go inherits the colon-equals for the inferred-type definition, but not the colon for type ascription, yet another way in which it could have been beautiful but isn’t.
- gingerBill 4y agoIt's slightly older than Limbo, and comes from Newsqueak. The difference is that Newsqueak used keywords for the other non-variable declarations. `x: int = 123`, `const X: int = 123`, `type My_Int: int`, etc.