[Tfug] Language wars ( was Language choices )
Joe Blais
joe.blais at pti-instruments.com
Thu Nov 2 12:43:18 MST 2006
Well ---
We used __closure to do callback functions. C, with everything being kind
of global, just needs a simple pointer to a function to call it indirectly.
C++ I thought really didn't support pointers to functions that were not part
of the same class, or not global, because the pointer to the function alone
doesn't know which instance of the class to use. The closure stuff just
provides enough information to know the instance -- that's how it was
espalned to me....
Borland winders stuff used something like this, never really did get
mikzroflbt to compile and work correctly (which is probably why their
threads had to be global). Don't know about GNU.
typedef void (__closure * WriteEventFunc)(const char * Buffer, const int
Size);
class mailslotserver
{
public:
//
// Func - event callback called when a datagram is recieved.
//
mailslotserver(const std::string &Name, const WriteEventFunc Func);
~mailslotserver();
there were things like __fastcall, __closure, __stdcall that prefixed all
function types,
something like "void Foo(void){}" really turned into "__stcall void
Foo(void){}" different complers did different things, depending on settings.
I don't know Perl and such, but I imagine the concept is the same for any
object oriented languge.
Joe
-----Original Message-----
From: tfug-bounces at tfug.org [mailto:tfug-bounces at tfug.org]On Behalf Of
Robert Hunter
Sent: Thursday, November 02, 2006 11:12 AM
To: Tucson Free Unix Group
Subject: Re: [Tfug] Language wars ( was Language choices )
Tim, some interesting points, but just want to clear up a few things...
> "Anonymous function" is too long to type, of course. Closure sounds
> best. And reminds me of ladies foundation garments, which is a
> pleasant association.
An anonymous function is not necessarily a closure. A closure is
function which in some way "captures" the state of it's environment, or
in computer science lingo, *refers to the free variables in its lexical
context. Anonymous functions are just functions that are not bound to a
name. Perhaps in some languages construction of a closure requires the
use of an anonymous function, but technically they are not the same.
*http://en.wikipedia.org/wiki/Closure_%28computer_science%29
> If we had more high-level functions (functions taking function params)
> we would begin to realize that we don't need comps and generators
> nearly as much as we think we do.
Do you mean "higher-order" functions? And what is a "comp"?
> Actually, having blocks greatly reduces the number of things you need
> the language to do for you, including "if" and "case".
Can you give an example?
> It amazes me how much language syntax the closure mechanism obviates.
> Switch/case is just a dictionary with some value-based key and a
> closure for a value. Iterating a tree is just a matter of passing a
> closure to a general function that iterates.
Once again, I think you are confusing a closure with a function
reference. Notice that some of these things you mentioned can be
accomplished in C, a language in which you can't construct closures. For
example, consider the qsort function in C. The function pointed to by
"compar" defines the actual order that is used by the underlying sorting
algorithm. It is not a closure.
void
qsort( void *base,
size_t nmemb, size_t size,
int(*compar)(const void *, const void *) );
By the way, speaking of other languages in which you *can* use closures,
don't forget about Scheme and Perl ;-)
http://en.wikipedia.org/wiki/Closure_(computer_science)#Programming_language
s_with_closures
Just my $2e-2...
--
Rob
_______________________________________________
Tucson Free Unix Group - tfug at tfug.org
Subscription Options:
http://www.tfug.org/mailman/listinfo/tfug_tfug.org
--
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.0.405 / Virus Database: 268.11.7/434 - Release Date: 8/30/2006
--
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.0.405 / Virus Database: 268.11.7/434 - Release Date: 8/30/2006
More information about the tfug
mailing list