Previous section: 3. Variables

Dylan reference manual -- Module Variables

Module Variables

Module variables can be referenced from anywhere inside the module. They play the role assumed by global variables in other languages.
define variable bindings = init	[Definition]
define variable creates module variables in the current module.

bindings are the variable(s) to be created, and mayhave the following forms:


or ( { variable }* [ #rest rest-variable-name ] )

where variable may be either variable-name or variable-name :: type. The variable-names and rest-variable-name must have the syntax of variable names, and are not evaluated. The values returned by init provide the initial values for the variable(s) specified by bindings.

In the simplest case, bindings is just a variable name, and init returns one value which is used to initialize that variable. See Checking Types and Binding Multiple Values for more complex cases.

? define variable foo = 10;
? foo + foo;
define constant bindings = init	[Definition]
define constant creates read-only module variables in the current module. This form has the same syntax and semantics as define variable except that the variables created are read-only.

Several other forms create module variables. See define class, define generic, and define method for more information.

Source code is associated with a specific module through the programming environment. This association occurs at development time and cannot be changed at run-time. See the Modules chapter for more details about modules. A given module variable can only be defined once, except that multiple define method definitions with different specializers are allowed, together with at most one define generic definition.

Next section: Lexical Variables