DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

(guile.info.gz) Variables

Info Catalog (guile.info.gz) Dynamic Libraries (guile.info.gz) Modules
 
 31.5 Variables
 ==============
 
 Each module has its own hash table, sometimes known as an "obarray",
 that maps the names defined in that module to their corresponding
 variable objects.
 
    A variable is a box-like object that can hold any Scheme value.  It
 is said to be "undefined" if its box holds a special Scheme value that
 denotes undefined-ness (which is different from all other Scheme values,
 including for example `#f'); otherwise the variable is "defined".
 
    On its own, a variable object is anonymous.  A variable is said to be
 "bound" when it is associated with a name in some way, usually a symbol
 in a module obarray.  When this happens, the relationship is mutual:
 the variable is bound to the name (in that module), and the name (in
 that module) is bound to the variable.
 
    (That's the theory, anyway.  In practice, defined-ness and bound-ness
 sometimes get confused, because Lisp and Scheme implementations have
 often conflated -- or deliberately drawn no distinction between -- a
 name that is unbound and a name that is bound to a variable whose value
 is undefined.  We will try to be clear about the difference and explain
 any confusion where it is unavoidable.)
 
    Variables do not have a read syntax.  Most commonly they are created
 and bound implicitly by `define' expressions: a top-level `define'
 expression of the form
 
      (define NAME VALUE)
 
 creates a variable with initial value VALUE and binds it to the name
 NAME in the current module.  But they can also be created dynamically
 by calling one of the constructor procedures `make-variable' and
 `make-undefined-variable'.
 
    First-class variables are especially useful for interacting with the
 current module system ( The Guile module system).
 
  -- Scheme Procedure: make-undefined-variable
  -- C Function: scm_make_undefined_variable ()
      Return a variable that is initially unbound.
 
  -- Scheme Procedure: make-variable init
  -- C Function: scm_make_variable (init)
      Return a variable initialized to value INIT.
 
  -- Scheme Procedure: variable-bound? var
  -- C Function: scm_variable_bound_p (var)
      Return `#t' iff VAR is bound to a value.  Throws an error if VAR
      is not a variable object.
 
  -- Scheme Procedure: variable-ref var
  -- C Function: scm_variable_ref (var)
      Dereference VAR and return its value.  VAR must be a variable
      object; see `make-variable' and `make-undefined-variable'.
 
  -- Scheme Procedure: variable-set! var val
  -- C Function: scm_variable_set_x (var, val)
      Set the value of the variable VAR to VAL.  VAR must be a variable
      object, VAL can be any value. Return an unspecified value.
 
  -- Scheme Procedure: variable? obj
  -- C Function: scm_variable_p (obj)
      Return `#t' iff OBJ is a variable object, else return `#f'.
 
Info Catalog (guile.info.gz) Dynamic Libraries (guile.info.gz) Modules
automatically generated byinfo2html