Scopes

On this page

A scope is a named place to store variables. Scripts, functions, classes and web requests each provide context for the values you use.

Scripts and functions

At script level, bare names and variables refer to script variables. Inside functions, use var or local for local values and arguments for parameters.

function greet( name, greeting = "Hello" ) {
    var message = greeting & ", " & arguments.name;
    return message;
}

println( greet( "Ann" ) );
println( greet( greeting = "Hi", name = "Bob" ) );
Hello, Ann
Hi, Bob

Closures

A closure can use values from its enclosing function:

function adder( amount ) {
    return value => value + amount;
}

addFive = adder( 5 );
println( addFive( 10 ) );
15

Classes

Inside a class, this holds public state and variables holds private instance state. See classes.

Web scopes

When serving templates, MatchBox provides scopes for the current request:

ScopeContents
urlQuery-string parameters.
formPosted form fields.
cookieRequest cookies.
sessionState associated with the session cookie.
cgiRequest information such as the method and path.

Web scopes belong to the server environment, not an ordinary CLI script. Session storage and application lifecycle depend on the server you use; see Web server.

Edit this page Download Markdown Last updated Oct 27, 2026, 1:45:34 PM Report an issue