2 ms·
To be frank, I am not sure of the specifics. At first I thought it was because anonymous functions have a notion of the lifetime of the variables they close ove
by catnaroek 13y ago
To be frank, I am not sure of the specifics. At first I thought it was because anonymous functions have a notion of the lifetime of the variables they close over, which named functions do not. However, taking into account that named functions do not close over anything in first place, this suggests that one should be able to use a named function wherever an anonymous function is expected.
- Touche 13y agoYou can use named functions interchangeably with anonymous functions, it's not just practical because of pointers.
- catnaroek 13y agoI stand corrected. Indeed, this program worked just fine: fn foo() { println("hai") } fn main() { let xs = ~[1,2,3]; for _ in xs.iter() { std::task::spawn(foo) } }