(guile.info.gz) Top Level
Info Catalog
(guile.info.gz) Binding Constructs
(guile.info.gz) Local Bindings
25.1 Top Level Variable Definitions
===================================
On the top level of a program (i.e. when not inside the body of a
procedure definition or a `let', `let*' or `letrec' expression), a
definition of the form
(define a VALUE)
defines a variable called `a' and sets it to the value VALUE.
If the variable already exists, because it has already been created
by a previous `define' expression with the same name, its value is
simply changed to the new VALUE. In this case, then, the above form is
completely equivalent to
(set! a VALUE)
This equivalence means that `define' can be used interchangeably with
`set!' to change the value of variables at the top level of the REPL or
a Scheme source file. It is useful during interactive development when
reloading a Scheme file that you have modified, because it allows the
`define' expressions in that file to work as expected both the first
time that the file is loaded and on subsequent occasions.
Note, though, that `define' and `set!' are not always equivalent.
For example, a `set!' is not allowed if the named variable does not
already exist, and the two expressions can behave differently in the
case where there are imported variables visible from another module.
-- Scheme Syntax: define name value
Create a top level variable named NAME with value VALUE. If the
named variable already exists, just change its value. The return
value of a `define' expression is unspecified.
The C API equivalents of `define' are `scm_define' and
`scm_c_define', which differ from each other in whether the variable
name is specified as a `SCM' symbol or as a null-terminated C string.
-- C Function: scm_define (sym, value)
-- C Function: scm_c_define (const char *name, value)
C equivalents of `define', with variable name specified either by
SYM, a symbol, or by NAME, a null-terminated C string. Both
variants return the new or preexisting variable object.
`define' (when it occurs at top level), `scm_define' and
`scm_c_define' all create or set the value of a variable in the top
level environment of the current module. If there was not already a
variable with the specified name belonging to the current module, but a
similarly named variable from another module was visible through having
been imported, the newly created variable in the current module will
shadow the imported variable, such that the imported variable is no
longer visible.
Attention: Scheme definitions inside local binding constructs (
Local Bindings) act differently ( Internal Definitions).
Info Catalog
(guile.info.gz) Binding Constructs
(guile.info.gz) Local Bindings
automatically generated byinfo2html