flip function

From: Date: Sun, 07 Jul 2002 23:12:45 +0000
Subject: flip function
Groups: php.general 
Request: Send a blank email to php-general+get-105976@lists.php.net to get a copy of this message
Hi all, Call me crazy if you want but I'm programming Haskell Code in PHP :-). I need some help to find a way to implement the Haskell flip function. Let me introduce flip: Flip receives two arguments: arg1 and arg2 arg1 must be the name of a function taking two arguments, name it f(x1,x2) arg2 is any variable Flip returns a function taking one argument, name it g(x), if you call g(foo) then the result will be the same as calling f(foo,arg2). Example: function add($x1,$x2) {return $x1+$x2;} $newfunc = flip("add",23); $result = $newfunc(12); // $result should be 23+12 I've tried with create function, for example: function flip($f,$arg) { return create_function('$y','return '.$f."($arg".',$y);'); } But if you use flip("foo",$o1) where o1 is an object then it won't work. There should be some workaround using references and who knows what... but I'm too old to find it, ideas? Garland.

« previous php.general (#105976) next »