Re:How an Engineering Company Chose to Migrate to D
by Rusky on Wednesday June 20, 2018 @05:39PM
(#17360028)
That's usually what "capture" means when talking about closures.
[ Parent
| on HN ]
Re:How an Engineering Company Chose to Migrate to D
by tikue_ on Wednesday June 20, 2018 @05:49PM
(#17360116)
At least in Rust, capture granularity is per-variable, so I think closures don't contain a stack frame pointer? Though, I'm not sure why this would matter to a user evaluating Rust's closures vs. D's nested fns?
Re:How an Engineering Company Chose to Migrate to D
by steveklabnik on Wednesday June 20, 2018 @05:57PM
(#17360173)
It’s a pointer to the environment, and a pointer to the function. So yes, not a stack frame pointer.
The environment is a struct containing what is captured; so for example, it would contain an &T if your closure captures a T by reference. You don’t need to walk a set of stack pointers to find it, just follow the reference directly there.
Re:How an Engineering Company Chose to Migrate to D
by WalterBright on Wednesday June 20, 2018 @06:27PM
(#17360405)
That's distinctly different from D's, which has a pointer to the enclosing stack frame.
If it is the enclosing function, it's just a single pointer to it. The "walking" comes from if you're accessing the enclosing function's enclosing function's frame.
Re:How an Engineering Company Chose to Migrate to D
by steveklabnik on Wednesday June 20, 2018 @07:34PM
(#17360857)
Makes perfect sense, thanks. I’m now wondering about the trade offs of these two approaches...