f



What's the C++ community's feeling about lambda(or closure) in C++?

I know this topic sounds kind of old and dry(and shallow, maybe :)),
but, you see, lately I found that there's all the fuss about closure in
Java, so I poked around for a little, and did find some valuable
information.

And I started to remember that there were a proposal(actually two)
about lambda/closure for C++(see
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n1968.pdf and
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n1958.pdf)
They're all pretty well-formed and sound, though I found Bjarne's a
little more comprehensive.

It simply seems that the closure idea is a good idea( I mean, I did
already think of it as a good idea since I met functional programming
languages a long time ago, but it was recently, invoked by the emerging
of the java closure, that I found it really a kinda sweet sugar for
C++).

I think there might be many people who have the experience of being
tripped when using std::for_each or alike. So, what's the community's
feeling about this feature?

p.s. Any *real* data about how much coding it would've saved would be
great :)


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
pongba (17)
12/21/2006 2:42:03 PM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8509) is leader. Post Follow

8 Replies
902 Views

Similar Articles

[PageSpeed] 29

pongba@gmail.com wrote:
> I know this topic sounds kind of old and dry(and shallow, maybe :)),
> but, you see, lately I found that there's all the fuss about closure in
> Java, so I poked around for a little, and did find some valuable
> information.
>

Have you look at the Boost.Lambda?

http://www.boost.org/doc/html/lambda.html

>
> It simply seems that the closure idea is a good idea( I mean, I did
> already think of it as a good idea since I met functional programming
> languages a long time ago, but it was recently, invoked by the emerging
> of the java closure, that I found it really a kinda sweet sugar for
> C++).

Yes, closure is very sweet. The library like Boost.Lambda gives C++
programmer some of the power in functional programming language,
e.g. lisp.

Regards
cg


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
cg
12/26/2006 8:26:00 PM
cg wrote:

> [..] The library like Boost.Lambda gives C++
> programmer some of the power in functional programming language,
> e.g. lisp.

I've written on this topic in this forum in the past, but I'm compelled
to repeat myself.

While the Boost Lambda Library might be useful, there are many thing
inherent to C++ that make it horribly awkward for genuine functional
programming--not the least of which is the fact that true closures imply
automatic memory management.

Here's a program I wrote in Standard ML specifically to illustrate the
expressive power of functional programming, and how it will never be
captured by a language like C++:

	http://www.standarddeviance.com/lex.sml

It's basically a small library of functions that the programmer can
compose into a lexical regular-expression pattern matcher. At the end is
an example where a function for matching floating-point numbers is
built. Without the comments, the whole thing is about a page of code.

-thant


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Thant
12/27/2006 9:49:30 AM
Thant Tessman wrote:

> While the Boost Lambda Library might be useful, there are many thing
> inherent to C++ that make it horribly awkward for genuine functional
> programming--not the least of which is the fact that true closures imply
> automatic memory management.

C++ already has automatic memory management.
It's the automatic storage, also known as the stack.

-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Mathias
12/28/2006 4:40:25 AM
In article <459301ba$0$26468$426a34cc@news.free.fr>, Mathias Gaunard
<loufoque@remove.gmail.com> writes
>Thant Tessman wrote:
>
>> While the Boost Lambda Library might be useful, there are many thing
>> inherent to C++ that make it horribly awkward for genuine functional
>> programming--not the least of which is the fact that true closures imply
>> automatic memory management.
>
>C++ already has automatic memory management.
>It's the automatic storage, also known as the stack.

True, but the problems are shared memory between threads and dynamic
memory. Those also need management and it is particularly hard with the
current guarantees.


-- 
Francis Glassborow      ACCU
Author of 'You Can Do It!' and "You Can Program in C++"
see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Francis
12/28/2006 7:09:55 PM
pongba@gmail.com wrote:
> I know this topic sounds kind of old and dry(and shallow, maybe :)),
> but, you see, lately I found that there's all the fuss about closure in
> Java, so I poked around for a little, and did find some valuable
> information.
>
> And I started to remember that there were a proposal(actually two)
> about lambda/closure for C++(see
> http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n1968.pdf and
> http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n1958.pdf)
> They're all pretty well-formed and sound, though I found Bjarne's a
> little more comprehensive.
>
> It simply seems that the closure idea is a good idea( I mean, I did
> already think of it as a good idea since I met functional programming
> languages a long time ago, but it was recently, invoked by the emerging
> of the java closure, that I found it really a kinda sweet sugar for
> C++).

The main problem with all these syntactic sugar issues is that it takes
the C++ committees time away from the real issues.  The real issues
being getting a comprehensive set of C++ libraries to try to match
those in Java and C#.

Java has the libraries so it can spend time on the sugar.

Any language changes rely on having a compiler support them and as C++
compiler is extremely complex anyway the effect of any language change
is to reduce the number of C++ compilers.

New standard libraries OTOH add more functionality for beginners and
can work with existing compilers. Libaries can be upgraded to
optionally support new features


regards
Andy Little


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
kwikius
12/29/2006 8:14:41 PM
I surely did, a long long time ago :)
As a brilliant library as that is, it has its warts, which are listed
in the official lambda proposal( links given in the OP).
cg wrote:
> pongba@gmail.com wrote:
> > I know this topic sounds kind of old and dry(and shallow, maybe :)),
> > but, you see, lately I found that there's all the fuss about closure in
> > Java, so I poked around for a little, and did find some valuable
> > information.
> >
>
> Have you look at the Boost.Lambda?
>
> http://www.boost.org/doc/html/lambda.html
>
> >
> > It simply seems that the closure idea is a good idea( I mean, I did
> > already think of it as a good idea since I met functional programming
> > languages a long time ago, but it was recently, invoked by the emerging
> > of the java closure, that I found it really a kinda sweet sugar for
> > C++).
>
> Yes, closure is very sweet. The library like Boost.Lambda gives C++
> programmer some of the power in functional programming language,
> e.g. lisp.
>
> Regards
> cg

-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
pongba
12/30/2006 4:33:42 PM
cg wrote:
> pongba@gmail.com wrote:
> > I know this topic sounds kind of old and dry(and shallow, maybe :)),
> > but, you see, lately I found that there's all the fuss about closure in
> > Java, so I poked around for a little, and did find some valuable
> > information.
> >
>
> Have you look at the Boost.Lambda?
>
> http://www.boost.org/doc/html/lambda.html

I surely did, a long long time ago :)
As a brilliant library as that is, it has its warts, which are listed
in the official lambda proposal( links given in the OP).


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
pongba
12/30/2006 4:34:31 PM
[snipped]
> The main problem with all these syntactic sugar issues is that it takes
> the C++ committees time away from the real issues.  The real issues
> being getting a comprehensive set of C++ libraries to try to match
> those in Java and C#.
> 
> Java has the libraries so it can spend time on the sugar.
> 
> Any language changes rely on having a compiler support them and as C++
> compiler is extremely complex anyway the effect of any language change
> is to reduce the number of C++ compilers.
> 
> New standard libraries OTOH add more functionality for beginners and
> can work with existing compilers. Libaries can be upgraded to
> optionally support new features
> 
> 
> regards
> Andy Little
> 
> 

My team of developers and I are currently working on a project to do
just this. It is called Power C++, and can be found on sourceforge:
http://sourceforge.net/projects/powercpp

Anyone interested in working on the project or in giving
suggestions/feature requests can contact me at
michaelsafyan@users.sourceforge.net .


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Michael
1/19/2007 6:39:33 AM
Reply: