Is every function a closure?

Yes, exactly. As you’ve identified, every function in JavaScript is a closure over at least one context: The global context. That’s how/why global variables work in JavaScript. We don’t normally call them closures unless they close over some other context and actually make use of the fact that they do, but you’re quite right that … Read more

How to use Swift @autoclosure

Consider a function that takes one argument, a simple closure that takes no argument: func f(pred: () -> Bool) { if pred() { print(“It’s true”) } } To call this function, we have to pass in a closure f(pred: {2 > 1}) // “It’s true” If we omit the braces, we are passing in an … Read more

Can you clone a closure?

What you are trying to do is call a closure from multiple threads. That is, share the closure across multiple threads. As soon as the phrase “share across multiple threads” crosses my mind, my first thought is to reach for Arc (at least until RFC 458 is implemented in some form, when & will become … Read more