/[guile]/guile/guile-core/doc/ref/scheme-modules.texi
ViewVC logotype

Diff of /guile/guile-core/doc/ref/scheme-modules.texi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by ossau, Fri Nov 16 15:04:16 2001 UTC revision 1.4 by ossau, Sat Dec 1 15:53:04 2001 UTC
# Line 32  designed languages: ML, Python, Perl, an Line 32  designed languages: ML, Python, Perl, an
32  clutter the global name space.  clutter the global name space.
33  @cindex name space - private  @cindex name space - private
34    
35    In addition, Guile offers variables as first-class objects.  They can
36    be used for interacting with the module system.
37    
38  @menu  @menu
39  * Scheme and modules::          How modules are handled in standard Scheme.  * Scheme and modules::          How modules are handled in standard Scheme.
40  * The Guile module system::     How Guile does it.  * The Guile module system::     How Guile does it.
41  * Dynamic Libraries::           Loading libraries of compiled code at run time.  * Dynamic Libraries::           Loading libraries of compiled code at run time.
42    * Variables::                   First-class variables.
43  @end menu  @end menu
44    
45    
# Line 827  the same place on all machines (which se Line 831  the same place on all machines (which se
831  anyway).  anyway).
832    
833    
834    @node Variables
835    @section Variables
836    @tpindex Variables
837    
838    A variable is a box-like object that can hold any Scheme value.  It is
839    said to be @dfn{undefined} if its box holds a special Scheme value that
840    denotes undefined-ness (which is different from all other Scheme values,
841    including for example @code{#f}); otherwise the variable is
842    @dfn{defined}.
843    
844    On its own, a variable object is anonymous.  A variable is said to be
845    @dfn{bound} when it is associated with a name in some way, usually a
846    symbol in a module obarray.  When this happens, the relationship is
847    mutual: the variable is bound to the name (in that module), and the name
848    (in that module) is bound to the variable.
849    
850    (That's the theory, anyway.  In practice, defined-ness and bound-ness
851    sometimes get confused, because Lisp and Scheme implementations have
852    often conflated --- or deliberately drawn no distinction between --- a
853    name that is unbound and a name that is bound to a variable whose value
854    is undefined.  We will try to be clear about the difference and explain
855    any confusion where it is unavoidable.)
856    
857    Variables do not have a read syntax.  Most commonly they are created and
858    bound implicitly by @code{define} expressions: a top-level @code{define}
859    expression of the form
860    
861    @lisp
862    (define @var{name} @var{value})
863    @end lisp
864    
865    @noindent
866    creates a variable with initial value @var{value} and binds it to the
867    name @var{name} in the current module.  But they can also be created
868    dynamically by calling one of the constructor procedures
869    @code{make-variable} and @code{make-undefined-variable}.
870    
871    First-class variables are especially useful for interacting with the
872    current module system (@pxref{The Guile module system}).
873    
874    @deffn {Scheme Procedure} make-undefined-variable
875    @deffnx {C Function} scm_make_undefined_variable ()
876    Return a variable that is initially unbound.
877    @end deffn
878    
879    @deffn {Scheme Procedure} make-variable init
880    @deffnx {C Function} scm_make_variable (init)
881    Return a variable initialized to value @var{init}.
882    @end deffn
883    
884    @deffn {Scheme Procedure} variable-bound? var
885    @deffnx {C Function} scm_variable_bound_p (var)
886    Return @code{#t} iff @var{var} is bound to a value.
887    Throws an error if @var{var} is not a variable object.
888    @end deffn
889    
890    @deffn {Scheme Procedure} variable-ref var
891    @deffnx {C Function} scm_variable_ref (var)
892    Dereference @var{var} and return its value.
893    @var{var} must be a variable object; see @code{make-variable}
894    and @code{make-undefined-variable}.
895    @end deffn
896    
897    @deffn {Scheme Procedure} variable-set! var val
898    @deffnx {C Function} scm_variable_set_x (var, val)
899    Set the value of the variable @var{var} to @var{val}.
900    @var{var} must be a variable object, @var{val} can be any
901    value. Return an unspecified value.
902    @end deffn
903    
904    @deffn {Scheme Procedure} variable? obj
905    @deffnx {C Function} scm_variable_p (obj)
906    Return @code{#t} iff @var{obj} is a variable object, else
907    return @code{#f}.
908    @end deffn
909    
910    
911  @c Local Variables:  @c Local Variables:
912  @c TeX-master: "guile.texi"  @c TeX-master: "guile.texi"
913  @c End:  @c End:

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26