spool-lang / Spool-Legacy-Repo

Legacy repo for the Spool programming language.
3 stars 0 forks source link

Scopes #16

Open RedstoneParadox opened 5 years ago

RedstoneParadox commented 5 years ago

Overview

The most basic form of scope is a block of code with it's own variables that can't be accessed outside of it like so:

{
    var foo = new Foo()

    {
        var bar = new Bar()
        foo.doFooThing()
        bar.doBarThing()
    }

    foo.doFooThing()
    bar.doBarThing() //Error
}

In the above example, foo and bar can both be accessed from within the inner scope block but when calling bar.doBarThing() in the outer scope, an error occurs as foo was dropped at the end of the inner scope.

Shadowing