Lugaru's Epsilon
Editor 14.04

Epsilon User's Manual and Reference
   . . .
   Introduction to EEL
      Epsilon Extension Language Features
      EEL Tutorial
   Epsilon Extension Language
      . . .
      The EEL Preprocessor
      Lexical Rules
      Scope of Variables
      Data Types
      . . .
   Primitives and EEL Subroutines
      Buffer Primitives
      Display Primitives
      File Primitives
      . . .
      Defining Language Modes
   . . .

Previous   Up    Next
String Constants  Epsilon Extension Language   Data Types

Epsilon User's Manual and Reference > Epsilon Extension Language >

Scope of Variables

Variables may have two different kinds of "lifetimes", or scopes. If you declare a variable outside of any function declaration, it is a global variable. If you declare it inside a function declaration, it is a local variable.

A local variable only exists while the function it is local to (the one you declared it in) is executing. It vanishes when the function returns, and reappears (with some different value) when the function executes later. If you call the function recursively, each call of the function has its own value for the local variable. You may also declare a variable to be local to a block, in which case it exists only while code inside the block is executing. A local variable so declared only has meaning inside the function or block it is local to.

A global variable exists independently of any function. Any function may use it. If functions declared in different source files use the same global variable, the variable must be declared in both source files (or in files #included by both files) before its first use. If the two files have different initializations for the variable, only the first initialization has effect.

If a local variable has the same name as a global variable, the local masks the global variable. All references in the block to a variable of that name, from the local variable's definition until the end of the block it is defined in, are to the local variable. After the end of the block, the name again refers to the global variable.

You can declare any global variable to be buffer-specific using the buffer keyword. A buffer-specific variable has a value for each buffer and a default value. The default value is the value the variable has when you create a new buffer (and hence a new occurrence of the buffer-specific variable). When you refer to a buffer-specific variable, you normally refer to the part that changes from buffer to buffer. To refer to the default portion, append ".default" to the variable name. For example, suppose the variable foo is buffer-specific. References to foo would then refer to the value associated with the current buffer. To refer to the default value, you would use the expression foo.default. (The syntax of appending ".default" is available only when writing EEL programs, not when specifying a variable name to set-variable, for example.) When you save Epsilon's state using the write-state command, Epsilon saves only the default value of each buffer variable, not the value for the current buffer.

Global variables may also be declared window-specific using the window keyword. A window-specific variable has a separate value for each window and a default value. When Epsilon starts from a state file, it uses the default value saved in the state file to set up the first window. When you split a window, the new window's variables start off with the same values as the original window. Epsilon also uses the default value to initialize each new pop-up window. You can append ".default" to refer to the default value of a window-specific variable.

Previous   Up    Next
String Constants  Epsilon Extension Language   Data Types

Lugaru Epsilon Programmer's Editor 14.04 manual. Copyright (C) 1984, 2021 by Lugaru Software Ltd. All rights reserved.