3 ms·
Wrong on all counts. Dynamic scoping depends on having a construct to introduce new scopes (a fancy way of saying 'let statement'). Here's what the classic pro
by sedachv 17y ago
Wrong on all counts. Dynamic scoping depends on having a construct to introduce new scopes (a fancy way of saying 'let statement').
Here's what the classic problem of "how do I test my code using a fake service?" would be solved with dynamic scoping:
(defvar service <default service>) ;; in Common Lisp you have to declare that certain variables will have dynamic scope, otherwise they would be lexical
(defun some-function ()
(use service))
(defun test ()
(let ((service <fake-test-service>))
(do-something (some-function))))
This is more than global variables, because now you can plug in any service you want in any runtime context you need without affecting other code.
If this looks a bit like AOP, it's because applying dynamic scope to functions is the actual underlying mechanism behind AOP: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.113.8305&rep=rep1&type=pdf http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.113...