What are the advantages of dynamic scoping?

后端 未结 10 927
迷失自我
迷失自我 2020-12-14 01:21

I\'ve learned that static scoping is the only sane way to do things, and that dynamic scoping is the tool of the devil, and results only from poor implementations of interpr

相关标签:
10条回答
  • 2020-12-14 01:42

    Dynamic Scoping breaks Referential Transparency, which means you cannot reason about the program any more. DS is basically global variables on steroids.

    0 讨论(0)
  • 2020-12-14 01:42

    This classic article by Richard Stallman (of GNU/Linux, Emacs, FSF) explains why dynamic scoping is important to the Emacs editor and the Emacs Lisp language. In sum, it is useful for customizing.

    http://www.gnu.org/software/emacs/emacs-paper.html#SEC17

    See also this page on the Emacs wiki, for more info about the use of dynamic scoping in Emacs Lisp:

    0 讨论(0)
  • 2020-12-14 01:46

    I think dynamic scope in Common LISP is analogy of Global Variable in C. Using them in a functional functions is problematic.

    0 讨论(0)
  • 2020-12-14 01:46

    An example whats convenient for me at the Emacs way of binding - not sure if lexical or dynamic is the right term BTW.

    A variable bound inside a let is seen downward, no explicit hand-over as argument needed, which saves a lot of keystrokes.

    (defun foo1 ()
      (message "%s" a))
    
    (defun foo2 ()
      (let ((a 2))
      (message "%s" a)))
    
    (defun foo3 ()
      (let ((a 1))
        (foo1)
        (foo2)))
    
    ==>
    1
    2
    

    Binding inside foo2 is of interest, as a usage of default values might be installed here

    (let ((a (if (eq something a) assign otherwise...

    0 讨论(0)
提交回复
热议问题