4 ms·
Common Lisp is much more dynamic in some ways, but much less dynamic in others. In PHP you can't redeclare functions or classes, while in Common Lisp you can. O
by jorams 8y ago
Common Lisp is much more dynamic in some ways, but much less dynamic in others. In PHP you can't redeclare functions or classes, while in Common Lisp you can. On the other hand, in PHP you can manipulate the current scope and make variables appear out of thin air, but you can't do stuff like that in Common Lisp.
For example in PHP:
$a = $_GET['greeting'] ?? 'hello';
eval('echo $a;'); // => hello, or an error or anything else if there is a query parameter called greeting.
$c = [ $a => eval('return "hi";') ];
extract($c);
echo $hello; // => hi, or an error or anything else if there is a query parameter called greeting.
While in CL:
(let ((a "hello"))
(eval 'a))
; => debugger invoked, the variable A is unbound.
A CL compiler can make a lot of assumptions about the local environment, and only has to account for real dynamicity in the global environment. For PHP it's basically the other way around. Since most optimizations seem to be relatively localized, that might be a real issue. But then, of course, a good compiler could fall back to unreasonable assembly wherever such dynamic features are used.
- deleted 8y ago[deleted]
- fiddlerwoaroof 8y agoYou can't manipulate the lexical environment using the standardized language, but sbcl and other lisps provide libraries for programatic manipulation of the lexical environment.
- fiddlerwoaroof 8y agoConceptually, you just need to add an extra layer of indirection to local variable lookup.
- lispm 8y agoBut we can use dynamic binding: CL-USER 29 > (let ((a "hello")) (declare (special a)) (eval 'a)) "hello"