News for hackers. Stuff that matters.
Re:Let's compile like it's 1992 (2014) by fuzztester on Tuesday February 27, 2024 @03:29PM (#39529413)
What is the difference between dynamic and lexical scope? And what are they? I googled it, but could not figure it out on a quick look, at least.

#lazyweb

Re:Let's compile like it's 1992 (2014) by trealira on Tuesday February 27, 2024 @03:45PM (#39529644)
Dynamic scope means you that whoever last bound the variable at runtime determines its value, not whichever outer scope surrounds it.

I guess it would be something like this in pseudo code:

  var dynamic = 5

  function foo() {
    print(dynamic)
  }
  
  function bar() {
    var dynamic = 6
    // foo() prints 6 due to the binding above
    foo()
    // After bar() exits, "dynamic" will go back to being 5
  }