[Tfug] Language wars ( was Language choices )
Robert Hunter
hunter at tfug.org
Thu Nov 2 11:12:26 MST 2006
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_languages_with_closures
Just my $2e-2...
--
Rob
More information about the tfug
mailing list