Keith Devens .com |
Friday, July 4, 2008 | ![]() |
| Je n'ai fait celle-ci plus longue que parce que je n'ai pas eu le loisir de la... – Blaise Pascal (Lettres Provinciales) | ||
|
| ← MSDN: C#: Create Elegant Code With Anonymous Methods, Iterators, And Partial Classes | Tags are so cool! → |

Harry Fuecks (http://www.phppatterns.com) wrote:
Keith (http://keithdevens.com/) wrote:
Thanks, last night I noticed that project mentioned from your J4P5 article linked from your PHP rant.
I looked at that part of the project, and I'm definitely not interested. Like every function uses an eval and they waste time and space defining things like id and not. They pretty much throw in the kitchen sink, including redefining a bunch of functional features that PHP already has. And sometimes they redefine things badly:
<?php
// The canonical "prepend" operation. Surely no faster than linear time,
// whereas a list-oriented language would do this in constant time.
// -- DB
function cons($val, $list) {
return array_merge(array($val), $list);
}
?>
Hello? What happened to array_unshift? These people are wankers trying to redefine Lisp in PHP (and doing it in a largely impractical way) rather than just using PHP.[1]
Plus, I already do use a largely functional style with PHP, and if I need any improvements (such as my mapfield) I can just define them myself.
Footnotes:
[1]: Note that their cons will copy all the elements of $list into a new array and return it. I know that was their intent when designing the library... everything copies and returns so that their library is more 'functional'. But this just supports my point that they're wankers.
Harry Fuecks (http://www.phppatterns.com) wrote:
...but interesting anyway. Some time I'd kinda like to do a "PHP Zoo" for strange projects people have done with it which are well out of the scope it's sanely used for.
Keith (http://keithdevens.com/) wrote:
Though, their fx function was a good idea:
<?php
/**
90% of lambda functions take one argument:
*/
function fx($body) {
return lam('$x', $body);
}
?>
So now I have:
<?php
function fx($body){ return create_function('$a',$body); }
function fxe($expr){ return fx("return $expr;"); }
function mapfield($key, $func=null){ return fxe("$func(\$a['$key'])"); }
?>
Joining in the wanking myself a tiny bit.
I definitely will mine the entire library for any other decent ideas.
Keith (http://keithdevens.com/) wrote:
Argh:
<?php
// Want the set difference?
// This computes setA - setB.
// Set members are represented as array values.
function set_difference($a, $b) {
assert(is_array($a));
assert(is_array($b));
$map = histogram($a);
foreach($b as $x) unset($map[$x]);
return array_keys($map);
}
?>
Or, you could just use array_diff.
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):
Generated in about 0.133s.
(Used 8 db queries)

You might be interested in this: http://metaphp.sourceforge.net/index.php?page=fp
The word "extension" is used in the sense of extension of the language (using PHP itself). Code in in the include.tgz - functional.php (http://sourceforge.net/projects/metaphp).