Boost logo

Boost :

From: Gabriel Dos Reis (gdr_at_[hidden])
Date: 2004-03-08 21:49:41


"Tanton Gibbs" <thgibbs_at_[hidden]> writes:

| > So I'm just wondering whether there is something in between the "no
| > reference to outside scopes" and full closures, which would hit the
| > sweet-spot for C++ better.
| >
| > Some visible client side syntax would be fine, and probably good,
| > to explicitly state what to do with such references (copy, create
| > a reference, ...)
|
| I've always been of the opinion that if you allowed the lambdas to curry,
| then you could pass in whatever outer level variables you need at the time
| of declaration and it would return back a function object representing the
| rest of the parameters needed.
|
| For instance:
|
| // loop through vec adding val to each of the elements
| int func(std::vector<int>& vec, int val) {
| std::for_each( arr.begin(), arr.end(),
| lambda (int v, int& elem ) {
| elem += v;
| }( val ) );
| }
|
| In the above example, the lambda takes two arguments, an int and an int
| reference. Then, we call the lambda with only one argument (the int
| parameter). This returns a new lambda that only takes one parameter (an int
| reference). With this syntax, you could explicitly pass in the outer level
| variables that you wanted to use and it is consistent with other functional
| programming languages. Also, this does not carry the overhead associated
| with closures or dynamic behavior or anything of the sort.

Yes, that is the stanadard version of lambda lifting.

OK, let's take this to private mails with Jaakko and come back when we
feel we have something :-)

-- Gaby


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk