#1690 It-block when assign closure

Yuri Strot Thu 3 Nov 2011

Closure type inference and it-blocks look so nature that I'm always missing this feature when define closure and assign it:

|Str| f := { echo(it) }

or

class A
{
  |Str| print

  new make() { print = { echo(it) } }
}

Does it make sense and can be implemented?

brian Fri 4 Nov 2011

It probably could be implemented, but it would definitely add a lot of complication to the grammar since today we only ever allow it-blocks after constructor/method calls.

But we also made a fairly deliberate design decision to limit where it-block syntax can be used - this goes back to the numerous discussions about control flow constructs, use of return inside it-blocks, etc. The final outcome of all that was sparing use of it-blocks and explicit use of |->| {} so that it was always very readable in the code where someone was using a closure.

Login or Signup to reply.