>>5
Correct; no lexical scoping and you have to store the functions in variables (which are strings) to access them, this works because...
>>4
It is a giant hack... observe this fully working PHP code!
<code>
<?php
function sum($term, $a, $next, $b)
{
if (function_exists($term) && function_exists($next))
{
var_dump($next);
$sum = 0;
for ($c = $a; $c <= $b; $c = $next($c))
{
$sum += $term($c);
}
}
else
{
return (-1);
}
return ($sum);
}
function identity($x) { return ($x); }
function increment($x) { return (++$x); }
function outp($contents)
{
echo('<p>'.$contents.'</p>');
}
echo('<html><head><title>SICPHP</title></head><body>');
outp('Sum of 1..5 = '.sum(identity, 1, increment, 5));
outp('Sum of 1"OOPS"5 = '.sum("identity", 1, "OOPS", 5));
outp('Ahem');
outp('Sum of increment(1, 3, 5) = '.sum("increment", 1, create_function('$x', 'return ($x + 2);'), 5));
$anon = "\0lambda_1";
outp('Anon is: '.$anon.'(2) = '.$anon(2));
?></code>