Name: Anonymous 2012-02-29 8:48
I really don't understand what the purpose of closures is. It seems to me that everything that can be written using closures, is just as easily written without. For example:
Wouldn't this be better written as:
Or at least defining the function outside of main() and referencing it inside? I just don't understand the benefit of closures.
void main()
{
int[] haystack = [345,15,457,9,56,123,456];
int needle = 123;
bool needleTest(int n)
{
return n == needle;
}
printf(find(haystack, &needleTest));
}Wouldn't this be better written as:
void main()
{
int[] haystack = [345,15,457,9,56,123,456];
int needle = 123;
foreach(int i : haystack)
{
if (i == needle)
{
printf(i);
}
}
}Or at least defining the function outside of main() and referencing it inside? I just don't understand the benefit of closures.