Well, it depends on what you expect. ;) I suspect you want index and value to be copied into a local store for each lambda when they are evaluated. But that would make them a lot less useful. For instance this example wouldn't work as I'd like:
int main() { int n = 0; function get_n = lambda() {return n;}; werror ("%O\n", get_n()); // Writes "0" n = 17; werror ("%O\n", get_n()); // Writes "17" }
And yes, that "workaround" is a decent way to make each generated lambda refer to its own set of variables.