Unnamed functions, functors or, more formally, function literals
Kris Warkentin
kewarken@qnx.com
Fri Mar 15 07:16:00 GMT 2002
I think that you haven't had much exposure to Lisp if you think that lambda
functions are rarely used and less than useful. In fact, these are very
popular features in Python and Perl as well as several other procedural
languages. Say I have some set of data upon which I would like to perform
arbitrary operations. Now I can pollute my namespace by defining functions
for every operation when I need it OR I can just pass an anonymous function
'object' to my mapping function and have it applied to every member of the
set. That way commonly used operations can be defined and 'one-off'
operations can be done anonymously.
I'm not saying that this should be added to C since, well, then it wouldn't
be C now would it? But I wouldn't write them off as less than useful. Try
using it for GUI programming some time. It's wonderful to pass a function
to be called when such and such button is pressed without having to define
it in the global or class namespace, especially if the action for the button
is something very simple.
cheers,
Kris
----- Original Message -----
From: "Paul Koning" <pkoning@equallogic.com>
To: <sd70030@lanet.lv>
Cc: <gcc@gcc.gnu.org>
Sent: Friday, March 15, 2002 9:30 AM
Subject: RE: Unnamed functions, functors or, more formally, function
literals
> >>>>> "Paul" == Paul V Andreev <sd70030@lanet.lv> writes:
> Paul> Names are only needed for shared functions! Unnamed function
> Paul> could became an idiom denoting "a helper function used only
> Paul> once".
>
> Names also make code more readable.
>
> Unnamed functions exist in one language I know of (Lisp). Admittedly
> I don't have much experience in that language, but from modest
> exposure to Elisp I have the impression that they are very rarely
> used.
>
> A rarely used feature in an esoteric language doesn't sound to me like
> something crying out to be added to C...
>
> paul
>
>
More information about the Gcc
mailing list