``` fun counter():()->Int{ var c=0 fun g():In...
# announcements
i
Copy code
fun counter():()->Int{
 var c=0
 fun g():Int{
  c++
  return c
 }
 return g
}
why “Function invocation g() expected”?
m
I guess you need to declare g a val ?
Copy code
val g: (() -> Int) = {
   c++
   c
}
d
Try
return ::g
?
i
but g is a function, I cannot return a function?
ok, ::g is ok, weird syntax, why it shouldn’t be like return variable?
d
g
isn't a variable. To return it like a variable you have to do what @mbonnin described.
m
You need an instance of a function type. It's explained there: https://kotlinlang.org/docs/reference/lambdas.html#instantiating-a-function-type
i
Copy code
val counter:()->()->Int = {
 var c=0
 val g = {
  c++
  c
 }
 g
}
d
Copy code
val counter:()->()->Int = {
 var c=0
 {
  c++
  c
 }
}
🙂
i
wow
k
isn't
c++;c
equal to
++c
d
True
Copy code
val counter:()->()->Int = {
 var c=0
 {
  ++c
 }
}