Hi Ashwin --
I was hoping someone else would take this question, but since nobody
has...
Chapel's current lambda support was put together quickly by a summer
intern several years ago and has received very little attention since
then, unfortunately. The reference to "stopgap technology" in the
technical note on them
(http://chapel.cray.com/docs/latest/technotes/firstClassFns.html) is
intended to refer to this immaturity and lack of attention that they've
received. I think it's a feature that most of us would like to see mature
in the language, but to date, it hasn't made it to the top of our priority
lists.
I believe that when we've talked about whether lambdas should be able to
refer to variables after they leave scope in Chapel is a topic that we've
vacillated on over time and don't have a clear vision on (at least, that
I'm aware of). In any event, we don't currently have any mechanism to
capture variables in different ways as the C++ feature you mention.
If you'd like to move this (arguably stalled) conversation forward, I'd
recommend opening a GitHub issue posing the question and/or proposing an
approach for Chapel (with rationale) and I'll do what I can to get
interested people on the team to chime in on it to see if we can come to a
conclusion.
Thanks, and sorry that this feature has languished since its original
implementation,
-Brad
On Tue, 15 Aug 2017, Aji, Ashwin wrote:
Hi,
I had a question on how to control how variables are captured in
Chapel's lambda functions. Currently, it looks like the variables are
all captured by reference (at least this is what I see in the generated
C code). This is problematic if we have asynchronous lambda functions
used in conjunction with Futures.async or Futures.andThen, because the
asynchronous lambda function may execute at a point when the calling
context has already been popped off the stack. A classic example is the
loop index that the async lambda captures by reference will be invalid
when the lambda actually executes.
My question is how to capture the external variables by value in
lambdas, similar to how it can be done in C++ using the following lambda
capture notations [=] and [&].
Regards,
Ashwin
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers