I was wondering if we could have functions like `...
# language-proposals
d
I was wondering if we could have functions like
Copy code
topLevelFun() = Unit

class Foo {
    bar() {
        //
    }
    baz() = println("baz")
}
5
r
Why would you want that?
d
I know it is a function
r
I don't like it, but that's beside the point. Make sure you read channel topics before you post. In this case:
All discussion in this channel should begin with a use-case or proposal instead of a question.
d
Es6 has it
Use case is getting rid of noise
r
"Es6 has it" isn't really an argument, and I doubt many will consider it noise.
g
Es6 is dynamic language, so no type declarations required. It's also matter of parser simplicity. Also this change is breakable, sometimes you just cannot distinguish between local function declaration and function invocation: bar(){} is that function declaration or function bar invocation which returns another function with a single lambda argument?
1
r
The face that Kotlin allows declaring functions inside functions makes that last point quite significant.
1
a
this would be ambiguous
Copy code
class Foo {
    bar() {
    }
    
    fun bar(f: () -> Unit) { ... }
}
👍 2
b
How do you distinguish between local functions and function calls?
Copy code
class Foo {
    Val _baz = Baz()
    bar() : Baz {
        return _baz
    }

    qux() {
        hoge() // new local function returning Unit?
        bar() = Baz() // Syntax error trying to call bar(), or or shadowing it?
    }
}

class Baz