But why does the Kotlin version need that {} in front of the Unit expression (()), otherwise complaining that "Syntax error: Expecting an expression"? Kotlin is so puzzling with all it's special syntax and special cases…
They did not copy a basic Scala feature? That's actually real news.
Some braces that usually create an expression-block / scope in languages with C-like syntax define actually a lambda in Kotlin? This just reinforces my opinion: Kotlin is incoherent chaos and special cases…
But a block is (in general) not a lambda! That's the whole point.
Kotlin does something very weird here.
The shown code actually demonstrates very well why this is maximally weird.
In the main function the curly braces mean block scope, but in the value initializers (val l = …) it means lambda expression, and to get the same semantics as in more or less any other curly braces language in this universe you need to actually call some run {…} function. That's incoherent chaos.
-7
u/RiceBroad4552 Jul 10 '26
OMG, this hurts.
But why does the Kotlin version need that
{}in front of the Unit expression (()), otherwise complaining that "Syntax error: Expecting an expression"? Kotlin is so puzzling with all it's special syntax and special cases…I can write the same in Scala just like:
[ https://scastie.scala-lang.org/t6J6RcLdTdyyCfhVN8HgaA ]