function-literal

Which languages support *recursive* function literals / anonymous functions?

It seems quite a few mainstream languages support function literals these days. They are also called anonymous functions, but I don't care if they have a name. The important thing is that a function literal is an expression which yields a function which hasn't already been defined elsewhere, so for example in C, &printf doesn't count. E...

Default type-parametrized function literal class parameter

Is this an intended behavior or is it a bug? Consider the following trait (be it a class, doesn't matter): trait P[T] { class Inner(val f: T => Unit = _ => println("nope")) } This is what I would have expected: scala> val p = new P[Int] { | val inner = new Inner | } p: java.lang.Object with P[Int]{def inner: this.In...

How should I avoid unintentionally capturing the local scope in function literals?

I'll ask this with a Scala example, but it may well be that this affects other languages which allow hybrid imperative and functional styles. Here's a short example (UPDATED, see below): def method: Iterator[Int] { // construct some large intermediate value val huge = (1 to 1000000).toList val small = List.fill(5)(s...