Lambda Functions???

36 views
Skip to first unread message

James Grant

unread,
Dec 6, 1999, 3:00:00 AM12/6/99
to
Could someone give me a quick outline of what a Lambda function is? I have
seen them mentioned several times now, but I am not familiar with the
concept. If this is too trivial a request, then please direct me to where I
can find the information.

Thanks,

James Grant

[ Send an empty e-mail to c++-...@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]


Thant Tessman

unread,
Dec 6, 1999, 3:00:00 AM12/6/99
to

James Grant wrote:

> Could someone give me a quick outline of what a Lambda function is? I have
> seen them mentioned several times now, but I am not familiar with the
> concept. If this is too trivial a request, then please direct me to where I
> can find the information.

The lambda calculus was devised by Alonzo Church in the 1930s as a model
for computability. Lambda is not so much a function in itself as it is a
calculus for specifying how functions are built. Many programming
languages (especially of the Lisp family) are heavily inspired by lambda
calculus. What makes lambda magical is that it is how you write
functions that build other functions. The best place to learn about the
true power of lambda is "Structure and Interpretation of Computer
Programs" by Abelson, Sussman, and Sussman, which many think is the best
computer science textbook ever written.

C++ doesn't support the concept of lambda, but some of the simpler ways
lambda is used can be kinda sorta faked by using templates to create
objects that support function syntax. (In this newsgroup I've seen
function objects called 'functors', but the word 'functor' means
something else in other programming languages.)

Note that the concept of lambda is much simpler than attempts to
simulate it in C++ would lead one to believe.

-thant

Gabriel Dos_Reis

unread,
Dec 7, 1999, 3:00:00 AM12/7/99
to
Thant Tessman <th...@acm.org> writes:

| James Grant wrote:
|
| > Could someone give me a quick outline of what a Lambda function is? I have
| > seen them mentioned several times now, but I am not familiar with the
| > concept. If this is too trivial a request, then please direct me to where I
| > can find the information.
|
| The lambda calculus was devised by Alonzo Church in the 1930s as a model
| for computability. Lambda is not so much a function in itself as it is a
| calculus for specifying how functions are built. Many programming
| languages (especially of the Lisp family) are heavily inspired by lambda
| calculus. What makes lambda magical is that it is how you write
| functions that build other functions. The best place to learn about the
| true power of lambda is "Structure and Interpretation of Computer
| Programs" by Abelson, Sussman, and Sussman, which many think is the best
| computer science textbook ever written.

Indeed.

| C++ doesn't support the concept of lambda, but some of the simpler ways
| lambda is used can be kinda sorta faked by using templates to create
| objects that support function syntax.

Actually, any expression f such that f() (possibly with arguments) is
well defined should do. That includes objets of class type with
overloaded operator() or a pointer to function.

| ... (In this newsgroup I've seen


| function objects called 'functors', but the word 'functor' means
| something else in other programming languages.)

In Abstract Algebra, functor means an application from one category into
another category. By similarity, some languages (e.g. SML) use
'functor' to denote an entity that derive a type from a set of types
(an application from type to type). Actually the template
instanciation machinery is more close to functor in that sense than
functional objects do.

| Note that the concept of lambda is much simpler than attempts to
| simulate it in C++ would lead one to believe.

Yep. The difficult/tedious part being the construction of closure
that is a mean to accessing variable and a code to execute (the latter
being routinely implemented as a pointer to function or an overloaded
operator()).

--
Gabriel Dos Reis, dos...@cmla.ens-cachan.fr

Ran Shalgi

unread,
Dec 7, 1999, 3:00:00 AM12/7/99
to
>C++ doesn't support the concept of lambda, but some of the simpler ways
>lambda is used can be kinda sorta faked by using templates to create
>objects that support function syntax. (In this newsgroup I've seen

>function objects called 'functors', but the word 'functor' means
>something else in other programming languages.)
>

The term functor is more often used to mean "pointer to function".
Function objects are sometimes called functionoids (The C++ FAQ Book
uses this term, although the online C++ FAQ-lite doesn't).


Ran Shalgi
Expand Networks, Inc
http://www.expand.com

---
Replace 127.0.0.1 with expand.com when replying by e-mail

ppo...@my-deja.com

unread,
Dec 8, 1999, 3:00:00 AM12/8/99
to
In article <384bc...@nnrp1.news.uk.psi.net>,

"James Grant" <james...@roke.co.uk> wrote:
> Could someone give me a quick outline of what a Lambda function is?
I have
> seen them mentioned several times now, but I am not familiar with the
> concept. If this is too trivial a request, then please direct me to
where I
> can find the information.

You're familiar with temporary variables that have no names. A Lambda
function is a temporary function that has no name. "Lambda" is the
keyword used in LISP to signal that such a function is being defined.

A temporary variable with no name is only useful as part of a C++
expression. In C++ functions are not expressions, so C++ would need to
be extended for lambda functions to be of any use.


Sent via Deja.com http://www.deja.com/
Before you buy.

Reply all
Reply to author
Forward
0 new messages