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

JUST LEARNED ABOUT PHP CLOSURES

Name: Anonymous 2006-04-04 21:00

Wow I didn't know PHP had closures. I'm now using them all over the place.

Name: Anonymous 2006-04-04 21:04 (sage)

Ugh.

Name: Anonymous 2006-04-04 21:41

Um.. PHP doesn't have closures. So, what exactly are you using all over the place?

Name: Anonymous 2006-04-05 3:45

Closures are awesome. I use them all the time in Lisp and Ruby.

Name: Anonymous 2006-04-05 21:56

>>3

eval you idiot

Name: Anonymous 2006-04-05 22:26

>>5
Eval isn't a closure, you idiot.

Name: Anonymous 2006-04-06 0:59

>>1 example plz?

Name: Anonymous 2006-04-06 18:15

>>1 Example

Name: Anonymous 2006-04-06 20:25 (sage)

>>7
>>8
I've heard there are a lot of examples here: http://www.google.com/ and there: http://www.php.net/

Name: Anonymous 2006-04-06 21:25 (sage)

>>9 is full of shit.

Name: Anonymous 2006-04-06 22:36 (sage)

>>9
Example please.

Name: Anonymous 2006-04-07 3:36

>>10 example plz?

Name: Anonymous 2006-04-07 4:07

Create anonymous functions with create_function, like create_function('$a,$b','return ' . ($reverse ? '-' : '') . 'strcasecmp($a,$b)')
As you can see, you can reference outside variables. Not elegant, and not the easiest to write (either as I showed or using double quotes and escaping inside variable $), but does the job.

You can use anonymous functions for functions like array_map, array_filter, array_reduce, array_walk, array_walk_recursive, usort, and other functions (possibly your own) expecting or returning a callback. You can invoke variable functions like $x(lol).

Name: Anonymous 2006-04-07 4:28

Just use Ruby or Lisp.

Name: Anonymous 2006-04-07 6:07

>>14
Just STFU. I have yet to see how can you do web applications in LISP, and Ruby is alright but there's far more support and existing open sauce for PHP. (The fact it's simpler helps, but it also hurts because some PHP "programmers" suck, so I'm not counting it as an advantage or a disadvantage.)

Name: Anonymous 2006-04-07 6:18

An anonymous function isn't a closure. I don't know why so many people mix them up.

Name: Anonymous 2006-04-07 6:23

Talking about which, that's a really ugly way to make an anonymous fuction. Is that really an anonymous function...?

Name: Anonymous 2006-04-07 7:05

PHP is the java of web programming.

Name: Anonymous 2006-04-07 7:32

>>18
Not really. It lets you get stuff done without having to make a massive class hierarchy. It's kinda sucky, encourages bad style and attracts wannabe programmers who can't write decent code to save their life. I'd say it's the VB of web programming. Java would be the Java of web programming.

Name: Anonymous 2006-04-07 7:36

>>17
Yes, it is. create_function defines it on the fly and returns a name you can later call as $f(x). This name is a random string.

Name: Anonymous 2006-04-07 8:12 (sage)

Beware! This is merely a convenience function that generates a unique name for a regular function. It is *not* a closure or even an anonymous function. It is just a regular function that gets named for you.

Name: Anonymous 2006-04-07 9:52

>>21
Uh, you don't seem to understand how PHP functions work. They are passed by name. Name as in, a string with the function name. They are called by name too. You _need_ to generate a name to use your anonymous function, because that's what high-order functions use and expect. And yes, as far as you're concerned they are anonymous functions, just like other language's anonymous functions still have an address. The internal name is used to access its code just like addresses, and if you don't mess with addresses you don't mess with random generated names.

Name: Anonymous 2006-04-07 10:40

You _need_ to generate a name to use your anonymous function
lol php

Name: Anonymous 2006-04-07 10:48

php is for fags

Name: Anonymous 2006-04-07 11:38

>>24 speaks the truth.

Name: Anonymous 2006-04-07 11:48

>>13
maybe you should just put your whole program into a string and then write your own parser for it. then you can add some syntax for closures.

Name: Anonymous 2006-04-07 11:57

LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP LISP

Name: Anonymous 2006-04-07 12:07

>>23
Lol U, what's the practical difference between a name and an address?

Name: Anonymous 2006-04-07 13:08

>>14
Forget Ruby, Common Lisp is better.

Name: Anonymous 2006-04-07 14:31

>>29
I did suggest Lisp. These days I generally suggest Ruby as well, since people seem to have a parenthesis phobia and need some cuddly syntax to hold.

Name: Anonymous 2006-04-07 15:51

So I herd u like lisp

Name: Anonymous 2006-04-07 19:23

(equal '(everybody loves Lisp) t)

Name: Anonymous 2006-04-07 19:29

There's one Lisp lover in this thread making so much noise. He got to lean Lisp, so his e-peenor is enormous.

Name: Anonymous 2006-04-07 19:32 (sage)

>>33
(format t "STFU NOOB!")
(defun increase-e-peenor (size)
  (+ 1 (increase-e-peenor size)))

Name: Anonymous 2006-04-07 20:33 (sage)

Name: Anonymous 2006-04-07 21:06

>>35
All you can answer is some trolling link you found on the internet instead of thinking for yourself? That's pathetic in front of those who know why Lisp is superior to what is available today. Your inability to write clean and simple frameworks must be why you haven't answered my previous post.

Name: Anonymous 2006-04-08 4:01

>>36
what post?

Name: Anonymous 2006-04-08 7:17

>>34
Don't know what that does, but perhaps it's like
print "STFU NOOB!"
increase_e_peenor = lambda x: x + 1
only more obfuscated.

Name: Anonymous 2006-04-08 11:00

>>33
You're pretty stupid if you can't learn lisp on your own.

Name: Anonymous 2006-04-08 12:09 (sage)

>>39
You're pretty stupid if you learn Lisp on your own.

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