Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • Dynamic typing and dynamic scoping do not lead to each other. Dynamic scoping is rarely seen, and even less rarely without dynamic typing. I'm really curious why you make this statement. It's clear that you can have dynamic typing without dynamic scoping but I don't see how you can have dynamic scoping without dynamic typing. Going back to your first example, the type of the variable x that function f sees depends on who called f. Commented Sep 20, 2016 at 18:49
  • @Doval with static typing, dynamic scoping would be much more verbose. Since the required dynamic variables are part of the function contract, these variables and their types would have to be declared similar to normal function parameters. The requirement to declare these means a function can not be transparent to dynamic scoping, and inherits the dynamic variable requirements of all functions it calls in turn. Sounds familar? It leads to the same mess as Java's checked exceptions. See my edit for an example of a hypothetical Implicit Variable Java. Commented Sep 20, 2016 at 19:23
  • In my mind that's no longer dynamic scoping, but now I'm just splitting hairs. Scala implements something like that with its implicit parameters but the caller doesn't necessarily have to have implicit parameters. I just wanted to make sure I didn't misunderstand. Thanks. Commented Sep 20, 2016 at 19:29
  • In the first example, f would have to require one specific type for x and a program will not typecheck unless there is a x variable with correct type, or we need a generics system so that f can handle x variables of many types. Commented Sep 20, 2016 at 19:29
  • 1
    "The only common programming languages I know which support dynamic scoping are Perl and Bash" – Scheme introduced lexical scoping into the Lisp world, all Lisps before Scheme and some after it are dynamically scoped: Common Lisp, Emacs Lisp, newLisp, picoLisp. Also Logo, and most Shells, including PowerShell. Commented Sep 22, 2016 at 21:39