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

However it does require severe adjustments to the lifetime rules for automatic variables, and you have to be mindful of e.g. custom allocators.



Custom allocators are relatively easy handle with an API something like:

     void* closureheap(void (^)())
     size_t closuresize(void(^)())
Or, well, anything else that allows you to separate the step of allocating memory from it's initialization. (There are probably more representation-independent APIs that would be better, but this was just off the top of my head)

And, yes, mutable captured variables will not be shared across multiple duplications. Somewhat unconventional, but given the mental model of copying closures, I don't think it's a surprising behavior.




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

Search: