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

Pages: 1-4041-

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-23 10:59

Keep dreaming.

Name: Anonymous 2008-08-23 13:54

if you think having closures and namespacing makes a language respectable you're a nigger

a nigger, a nigger, a nigger I say
and the klu klutz klan is gonna make your day.
a nigger, a nigger, a nigger I say
and the klu klutz klan is gonna make your day.
a nigger, a nigger, a nigger I say
and the klu klutz klan is gonna make your day.
a nigger, a nigger, a nigger I say
and the klu klutz klan is gonna make your day.
a nigger, a nigger, a nigger I say
and the klu klutz klan is gonna make your day.

Name: Anonymous 2008-08-23 14:04

>>3
back to /b/, please

Name: Anonymous 2008-08-23 16:12

No one cares but toy languageists.

Name: Anonymous 2008-08-23 16:47

Name: Anonymous 2008-08-23 19:57

PHP now has a useful lambda feature. FIOC still doesn't.

FUCK.

Name: Anonymous 2008-08-23 20:03

closures and lambdas in c would be a lot more useful. c2009, anyone?

Name: Anonymous 2008-08-23 20:22

>>8
Wikipedia:

As of 2007, work has begun in anticipation of another revision of the C standard, informally called "C1x". The C standards committee has adopted guidelines to limit the adoption of new features that have not been tested by existing implementations.

If you want closures and lambdas in standard C, feel free to add them to gcc (|Intel CC|Microsoft CC if you happen to work on either team). That's the only way the ISO will even glance at a feature request.

Name: Anonymous 2008-08-23 20:57

>>7
Yes, this is like a pain in my cock, since I otherwise love Python.

>>8
GTFO

Name: Anonymous 2008-08-23 21:19

>>9
Ah, so ISO has finally realized they have no ability whatsoever to define the language, and should just stick to imitating GNU C so they can pretend to be relevant.

Name: Anonymous 2008-08-23 21:29

Grim Fandango music
 
 Also Frank Sinatra & Dean Martin because they are good regardless.

Name: Anonymous 2008-08-23 23:22

>>9
i'm adding them to my own version of tcc right now.
pcc is next.

Name: Anonymous 2008-08-24 0:00

#include <stdio.h>

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

int main(){
 int (*mult_by_2)(int, ...) = MAKE_FUNC({__ * 2;}, int, int);
 for(int i = 0; i < 10; ++i)
  printf("mult_by_2(%d) = %d\n", i, mult_by_2(i));
 return 0;
}


C >>> PHP

Name: Anonymous 2008-08-24 0:10

>>14
Faggot, this is piss ugly and not dynamic, what the fuck is this doing here? Read SICP for fuck's sake.

Name: Anonymous 2008-08-24 6:02

>>11
They've always looked at existing implementations - that's how they know the stuff has a chance of working in practice.

Name: Anonymous 2008-08-24 7:55

>>11
Truth

>>16
We don't need an organization of sodding ass-lickers such as ISO to tell us what works once it's implemented. Those fucking motherfuckers should just stick the OOXML specification up their humungous assholes and die from the AIDS it has.

Name: Anonymous 2008-08-24 11:52

>>14
I shat brix.

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;
}

Name: Anonymous 2008-08-25 9:35

>>19
If there are any commas in MAKE_FUNC's block argument, your shit's gonna break. To make it work properly, you're gonna have to do something like:

#define COMMA ,

and replace every "," for "COMMA" in MAKE_FUNC's block argument.

Name: Anonymous 2008-08-25 11:48

>>20
Or surround the block in parentheses.

Name: Anonymous 2008-08-25 12:23

>>8
No.

Name: Anonymous 2008-08-25 12:24

>>21
Seriously guys, I think you're going too far. I know it's stupid to tell this to Anonymous, but I wouldn't turn the respect we have for the Sussman into something he might not like if he saw it. And we're easily reachable via Google if you Google for Lisp-related stuff.

I see the Sussman as a super-hero, along with the Abelson. They're like Superman and Batman; the former is all about purity; the later is darker but gets the job done and does just as good a service to the world.

Name: Anonymous 2008-08-25 13:32

>>23
hahahaha

Name: Anonymous 2008-08-25 14:42

>>23
You weren't around several months ago when he actually talked to us, were you?

Name: lol !8mQB/2odm6 2008-08-25 14:44

>>25
Talked to me.

Name: Anonymous 2008-08-25 14:46

>>26
Shut up, tripfag.

Name: Anonymous 2008-08-25 14:59

>>27
You shut up, I spoke to the Sussman.

Name: Anonymous 2008-08-25 15:01

>>27
As far as I'm aware, lol!8mQB/2odm6 is not a real tripfag in that he normally posts with neither name nor tripcode, except when posting in the course of his Official /prog/-Sussman Liaison Officer duties.

Name: Anonymous 2008-08-25 15:09

>>26,29
Obvious samefag is obvious.

Name: Anonymous 2008-08-25 15:34

>>30
>>26,28 is me, sir. I have fans.

Name: Anonymous 2008-08-25 15:50

>>29
Holy shit. Spoiler has a secret.
Official -Sussman Liaison Officer then highlighting /prog/ is different than /prog/ and then Official -Sussman Liaison Officer

Name: Anonymous 2008-08-25 16:13

>>32
Official -Sussman Liaison Officer then highlighting /prog/ is different than /prog/ and then Official -Sussman Liaison Officer
There's something wrong with either your browser or youself,

Name: Anonymous 2008-08-25 16:16

>>25
Ooooh shit, I missed that; could you elaborate / post links to threads?

Name: Anonymous 2008-08-25 17:23

>>32,33
Firefox has always had issues with italics bleeding out from under [spoiler] tags.  Not sure about IE.

Name: Anonymous 2008-08-25 18:22

>>31
Multiple personalities do not count as fans, sir.

Name: Anonymous 2008-08-25 19:21

>>19
At first this was pretty cool to play with during class.  I was able to create a function that would sum all values of a function from a to b with an optional step size.  However, trouble occurred with nested lambda statements.  It just didn't work.  Also, Sussman's interpretation of cons, car, and cdr in one of his lectures doesn't work:

(define (cons a b)
  (lambda (m)
    (cond ((= m 0) a)
      ((= m 1) b)
      (else (error "Huh?")))))

(define (car x)
  (x 0))

(define (cdr x)
  (x 1))

It just doesn't work.  Still could be a bit useful for simple things.  Just don't be expecting a fully complex lisp system in C.

Name: Anonymous 2008-08-25 19:51

>>37
See Greenspun's Tenth Rule - that's the only way to get C to be anything useful.

Name: Anonymous 2008-08-25 20:04

Embedded spoilers aren't exactly special.

Name: Anonymous 2008-08-25 23:03

>>38
Or you could just try to think in C-style.  Sometimes it's just a bit better to use C.  Sometimes lisp.  Sometimes (yes) python.  The exact proportions vary all the time.  The C lambda thing (to me) was just a fun little experiment that also helped me with understanding a few of the exploitable features of C.

Name: Anonymous 2008-08-26 9:16

>>40
You mean GNU C.

Name: Anonymous 2008-08-26 14:10

>>41
it works just fine on my sun c compiler.

Name: Anonymous 2008-08-26 15:20

>>42
What about my sun c compiler?

Name: Anonymous 2008-08-26 15:23

In my sun c compiler?

Name: Anonymous 2008-08-26 20:11

>>44
It's more likely than you think.

Name: Anonymous 2008-08-26 21:08

>>42-45
Fuck off, this is my sun c compiler.

Name: Anonymous 2008-08-26 22:05

>>46
Enjoy your sun c compiler bitch.

Name: Anonymous 2008-08-26 22:32

>>47
I will, along with my dead-end job.

Name: Anonymous 2010-12-22 12:20

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