3 ms·
> Why would functions in a lisp-2 be more awkward than in a lisp-1? Jtsummers explained this quite well (as does the article). > PHP has been too long ago for
by chriswarbo 10y ago
> Why would functions in a lisp-2 be more awkward than in a lisp-1?
Jtsummers explained this quite well (as does the article).
> PHP has been too long ago for me to understand your comparison.
> Would you please explain it differently?
PHP has a function namespace, which is used by C-style function definitions (similar to 'defun'):
function foo(x) { return x; }
and a separate value namespace, which is used by anonymous functions (similar to 'lambda'):
$bar = function(x) { return x; };
Both sorts of function can usually[1] be called directly, e.g.
foo(42); // Returns 42
$bar(42); // Returns 42
Passing around functions as values is tricky though. It's easy for the lambda-style values:
array_map($bar, [0, 1, 2, 3])
For named functions, we have to provide a string containing the function's name, e.g.:
array_map('foo', [0, 1, 2, 3])
This is very similar to the quoting of names in a lisp-2 (although using strings seems much uglier to me).
[1] See https://news.ycombinator.com/item?id=8119419 https://news.ycombinator.com/item?id=8119419 for some (historical?) counterexamples