Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I like your C-like syntax better.

But I don't think there's any need to differentiate between different captures. Capture by value is enough because what do you need in C if you need a reference? Capture the value of the pointer.

    {
        void *chunk = malloc(x);
        
        defer (chunk, void **reference = &chunk) { ... }
        
        ...
    }
This would allow you to operate on the value both from the defer declaration time and defer execution time, whichever it is that you need.


That's an interesting point, and very C-like. You're right that capture-by-value can emulate capture-by-reference.

Capture-by-value does have a weakness though, in that it requires allocation (whether stack or heap). Capture-by-reference doesn't have any storage overhead.

In my example, I suggested having both. But if we had to pick only one, capture-by-value would be the one to use.




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

Search: