Up | Next | Prev | PrevTail | Tail |
Variables in PSL are ids, and associated values are usually stored in and retrieved from the value
cell of this id. If variables appear as parameters in lambda expressions or in prog’s, the contents
of the value cell are saved on a binding stack. A new value or nil is stored in the value cell and
the computation proceeds. On exit from the lambda or prog the old value is restored. This is
called the ”shallow binding” model of LISP. It is chosen to permit compiled code to do binding
efficiently. For even more efficiency, compiled code may eliminate the variable names and
simply keep values in registers or a stack. The scope of a variable is the range over which
the variable has a defined value. There are three different binding mechanisms in
PSL.
Local Binding | Only compiled functions bind variables locally. Local variables occur as formal parameters in lambda expressions and as prog form variables. The binding occurs as a lambda expression is evaluated or as a prog form is executed. The scope of a local variable is the body of the function in which it is defined. |
Fluid Binding | Fluid variables are global in scope but may occur as formal parameters or prog form variables. In interpreted functions, all formal parameters and local variables are considered to have fluid binding until changed to local binding by compilation. A variable can be treated as a fluid only by declaration. If fluid variables are used as parameters or locals they are rebound in such a way that the previous binding may be restored. All references to fluid variables are to the currently active binding. Access to the values is by name, going to the value cell. |
Global Binding | In theory global variables may never be used as parameters in lambda expressions or as prog variables. This restriction is not enforced in PSL. You are encouraged not to declare an identifier global if it is used as a parameter in a lambda expression or prog. For more information see the Section Fluid and Global Declarations, Chapter 19. |
⋆⋆⋆⋆⋆ ID cannot be changed to FLUID
⋆⋆⋆⋆⋆ ID cannot be changed to GLOBAL
Up | Next | Prev | PrevTail | Front |