KRASCHE
&
BYRNE
         ELZED  HOME       NEWS       DOCS       DOWNLOADS       LICENSING       SUPPORT       FAQ       ABOUT  US

What's An Elzed?
Features
Licensing
Downloads
Documentation
Elzed News
    ELZED 
 Documentation 
 Core Concepts 

Scope

You are probably already familiar with the concept of scope. In most high-level languages, variables declared within a particular function are at local scope, available only within that function. Variables declared "outside" all functions are at global scope and are (perhaps counterintuitively) available within all functions.

Similarly, Elzed variables are normally created at local scope and are available only within the expression in which they are created. You may, however, use scope modifiers to create variables at broader scopes. Using the "global" scope modifier, a variable can be made available throughout a context. Elzed extends conventional scoping to the "cosmic" level -- variables at cosmic scope are available in all contexts.

Operators also have scope. All internal Elzed operators have cosmic scope, and so are available in all contexts. External operators are declared with global or cosmic scope. Operators may not be declared at local scope.

local scope variable is available only in the given expression
global scope operator or variable is available only in one particular context
cosmic scope operator or variable is available in all contexts

Elzed operators and variables are created in a particular scope and exist in that scope throughout their lifetimes; there is no way, for example, to move a variable from one scope to another. Note also that variables created at global or cosmic scope will persist even after the expression in which they were created is destroyed.

Scope and context can interact in strange ways. For example, it's possible (and permissable) for two variables at global scope to have the same name, as long as they are in different contexts. In general, two identically-named Elzed objects can be at the same scope, or in the same context, but not both. For this reason, all variable names at cosmic scope (having no particular context) must be unique.

Local scope can also be slippery. Note that only variables can be declared at local scope. A variable is at local scope by virtue of not being declared cosmic or global. There is, however, a local scope modifier, so you can explicitly declare:

local number myNumber

Elzed variables and operators are found by scope. This means that, for example, when seeking a particular variable, first the expression's local list is checked, then the context's global list, and then finally Elzed's cosmic list. A variable at local scope will effectively "hide" identically named variables at global and/or cosmic scope.



  Copyright  ©  MMXXIV  by  R R Le Cropane   •   All Rights Reserved   •   Terms of Use   •   Privacy Policy