Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Closures, lambdas and namespaces in PHP 5.3

Name: Anonymous 2008-08-23 7:38

ttp://www.php.net/archive/2008.php#id2008-08-01-1

I have a dream that one day PHP will be a respectable programming language.

I have a dream that one day we'll download popular web applications that are free software and will not be outraged at their source code.

I have a dream that one day "designers" who were writing PHP would just give up and we'll get less PHP-Nuke hacks, and more decent software.

I have a dream today.

Name: Anonymous 2008-08-25 0:59

>>14
#include <stdio.h>

#define MAKE_FUNC(return_type, block, ...) ({\
  return_type _f(__VA_ARGS__){\
   return (block);\
  }\
  &_f;\
 })

int main(){
 int (*mult_by_2)(int) = MAKE_FUNC(int, {_1 * 2;}, int _1);
 for(int i = 0; i < 10; ++i)
  printf("2 * %d = %d\n", i, mult_by_2(i));
 for(int i = 0, j = 10; i < 10; ++i, --j)
  printf("%d * %d = %d\n", i, j, MAKE_FUNC(int, {_1 * _2;}, int _1, int _2)(i, j));  // this also works!
 return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List