Hacker News new | past | comments | ask | show | jobs | submit login

Trailing closures turn out to be magic when creating APIs and mini-DSLs. That slight reduction of friction that unifies regular language syntax with user-defined functions is often the difference between a high usable extension and a kludge.



Do you happen to have any good examples? They look like a great feature but I'm less familiar with how they've already been used in other languages.


Scala is full of many libraries that take advantage of trailing closures. I think their standard library Future/Promise API is good example: http://docs.scala-lang.org/overviews/core/futures.html

Edit: Another popular one is the ScalaTest unit testing framework: http://www.scalatest.org


Take a look at one of the tutorials on writing a Ruby DSL. E.g. http://rubylearning.com/blog/2010/11/30/how-do-i-build-dsls-...


I think Ruby is the major banner-carrier for this feature. It is actually more awkward in Ruby to have non-trailing closures.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: