Partial Evaluation
- Intent
- Produce a new function, by caching one or more of the original arguments
- Motivation
- Very often we use a function with one of it's complex arguments over and over again. We want to speed the avaluation.
- Implementation
- Use memoization to remember the argument
- Example
class p_eval {
private $args = null;
private $func = null;
function __construct($func,$args) {
$this->func = $func;
$this->args = $args
}
function evaluate($arg) {
call_user_func($this->func,array_push($this->args,$arg));
}
}
//usage
$f = array(new p_eval('a_function',array('one')), 'evaluate');
....
$f($arg);