defvar

Gamma: Version 4.0
Prev |  | Next

# `defvar`

`defvar` -- defines a global variable with an initial value.

## Syntax

    defvar (!symbol, value, constant_p?)

## Arguments

`symbol`

  A variable name which has not yet been assigned a value.

`value`

  Any s_exp.

`constant_p`

  If non-nil, the symbol will be assigned as a constant.

## Returns

The value of the symbol.

## Description

This function defines a global variable with an initial value. If the `constant_p` argument is present and non-nil, then the `symbol` becomes a constant, and any attempt to set its value in any scope will fail. If the `symbol` already has a value and `constant_p` is non-nil or absent, then `defvar` will return immediately with the current value of the `symbol`. If `constant_p` is non-nil and the `symbol` already has a value, then an error is generated.

The intent of `defvar` is to provide a value for a symbol only if that symbol has not yet been defined. This allows a Gamma or Lisp file to contain default symbol values which may be overridden before the file is loaded.

## Example

        Gamma> defvar(a,7,t);
        7
        Gamma> a;
        7
        Gamma> a = 5;
        Assignment to constant symbol: a
        debug 1>

        Gamma> b = 9;
        9
        Gamma> defvar(b,10);
        9
        Gamma> b;
        9
        Gamma>

## See Also

`set`

Prev | Home | Next
`defmethod` | Up | `destroy`

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.