Skip to content

Function Scopes & Namespaces

I think it'd be a good idea if functions had their own scopes, and whereby the user can request variables from a higher scope, albeit I wonder if it'd be better to just have a global scope and no upper scopes.

let var1 = "fizz"
fn parent
    let var2 = "buzz"
    fn child
        let var3 = "bazz"
        # Access global scope (highest level)
        echo ${global::var1}

        # Access the next scope up
        echo ${super::var2}

        # Access two scopes up
        echo ${super::super::var1}

        # Ensure access to current scope only
        echo ${local::var3}

        # Ensure access to environment variable
        echo ${E::PATH}
    end
    child
end

parent