Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

what are Lambda(s)? and Why use them?

64 views
Skip to first unread message

gdo...@gmail.com

unread,
May 19, 2016, 8:50:41 PM5/19/16
to
What are Lambda(s)? and Why use them?

Alf P. Steinbach

unread,
May 19, 2016, 9:13:01 PM5/19/16
to
On 20.05.2016 02:50, gdo...@gmail.com wrote:
> What are Lambda(s)? and Why use them?

A lambda expression creates and calls an instance of an automatically
generated class that has an operator(). So it's like an anonymous
function defined on the spot. The generated class can capture values and
references from the context, but by default it doesn't.

The name “lambda” is commonly used for anonymous functions in
programming, regardless of the programming language, and stems no doubt
from Church's ¹“lambda calculus” that the Lisp language was based on.

For details of the C++ lambda see the discussion over at ²cppreference.com.

× × ×

Instead of asking simple factual questions in clc++, better ask them
over at Stack Overflow.

Stack Overflow is Q&A site, catering to that kind of question.

clc++ is a discussion group, and there isn't much discussion in a simple
factual question unless someone posts a horribly wrong answer and
insists it is correct.

× × ×

Questions that can be discussed are however better asked here than on
SO. That's because SO is actively designed to not discourage
discussions. For example, one can't post formatted code in SO comments,
and SO moderators regularly tidy up discussion threads with often less
than perfect value judgment, or even recognition of what constitutes
necessary context for the comments left behind.


Cheers & hth.,

- Alf

¹ <url: https://en.wikipedia.org/wiki/Lambda_calculus>
² <url: http://en.cppreference.com/w/cpp/language/lambda>

Alf P. Steinbach

unread,
May 19, 2016, 9:15:08 PM5/19/16
to
On 20.05.2016 03:12, Alf P. Steinbach wrote:
> ...

Sorry, an extraneous “not” wormed its way into the text.

- Alf

Jerry Stuckle

unread,
May 19, 2016, 9:41:51 PM5/19/16
to
On 5/19/2016 9:12 PM, Alf P. Steinbach wrote:
<snip>
>
> Instead of asking simple factual questions in clc++, better ask them
> over at Stack Overflow.
>

I disagree. This is a perfectly good place to ask a "simple factual
question". But this is also more than a "simple factual question".

> Stack Overflow is Q&A site, catering to that kind of question.
>

It's OK for a website. But I much prefer usenet with a real news reader.

> clc++ is a discussion group, and there isn't much discussion in a simple
> factual question unless someone posts a horribly wrong answer and
> insists it is correct.
>

No, it is a usenet newsgroup.

<snip>

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstu...@attglobal.net
==================

Ben Bacarisse

unread,
May 20, 2016, 5:56:56 AM5/20/16
to
"Alf P. Steinbach" <alf.p.stein...@gmail.com> writes:

> On 20.05.2016 02:50, gdo...@gmail.com wrote:
>> What are Lambda(s)? and Why use them?
>
> A lambda expression creates and calls an instance of an automatically
> generated class that has an operator(). So it's like an anonymous
> function defined on the spot.

That "calls" might confuse some people. The lambda expression creates
an anonymous function (or function-like object) but it (the newly
created function) does not get called at that point. Maybe there was
more there once and an edit left it standing -- "... creates and calls
the constructor for ...".

(Obviously a lambda expression *can* be part of a larger function call
expression in which case it *will* be called immediately after its
creation, but it's not the lambda expression doing the calling.)

<snip>
--
Ben.

gdo...@gmail.com

unread,
May 21, 2016, 8:17:00 PM5/21/16
to

> Ben, Jerry, Alf,


Thanks,

g.

Alf P. Steinbach

unread,
May 21, 2016, 9:22:47 PM5/21/16
to
On 20.05.2016 11:56, Ben Bacarisse wrote:
> "Alf P. Steinbach" <alf.p.stein...@gmail.com> writes:
>
>> On 20.05.2016 02:50, gdo...@gmail.com wrote:
>>> What are Lambda(s)? and Why use them?
>>
>> A lambda expression creates and calls an instance of an automatically
>> generated class that has an operator(). So it's like an anonymous
>> function defined on the spot.
>
> That "calls" might confuse some people. The lambda expression creates
> an anonymous function (or function-like object) but it (the newly
> created function) does not get called at that point. Maybe there was
> more there once and an edit left it standing -- "... creates and calls
> the constructor for ...".

Thanks!


Cheers!,

- Alf

0 new messages