r7rs-small-texinfo

Unnamed repository; edit this file 'description' to name the repository.
git clone https://kaka.farm/~git/r7rs-small-texinfo
Log | Files | Refs | README | LICENSE

environments-and-evaluation.texinfo (3377B)


      1 @node Environments and evaluation
      2 @section Environments and evaluation
      3 
      4 @deffn {eval library procedure} environment @vari{list}@dots{}
      5 
      6 This procedure returns a specifier for the environment that results
      7 by starting with an empty environment and then importing each
      8 @var{list}, considered as an import set, into it. (@xref{Libraries}
      9 for a description of import sets.)  The bindings of the environment
     10 represented by the specifier are immutable, as is the environment
     11 itself.
     12 
     13 @end deffn
     14 
     15 @deffn {r5rs library procedure} scheme-report-environment version
     16 
     17 If @var{version} is equal to @code{5}, corresponding to @rfivers{},
     18 @code{scheme-report-environment} returns a specifier for an environment
     19 that contains only the bindings defined in the @rfivers{} library.
     20 Implementations must support this value of @var{version}.
     21 
     22 Implementations may also support other values of @var{version},
     23 in which case they return a specifier for an environment containing
     24 bindings corresponding to the specified version of the report. If
     25 @var{version} is neither @code{5} nor another value supported by the
     26 implementation, an error is signaled.
     27 
     28 The effect of defining or assigning (through the use of @code{eval})
     29 an identifier bound in a @code{null-environment} (for example
     30 @code{car}) is unspecified.  Thus both the environment and the bindings
     31 it contains may be immutable.
     32 
     33 @end deffn
     34 
     35 @deffn {r5rs library procedure} null-environment version
     36 
     37 If @var{version} is equal to @code{5}, corresponding to @rfivers{},
     38 the null-environment procedure returns a specifier for an environment
     39 that contains only the bindings for all syntactic keywords defined
     40 in the @rfivers{} library. Implementations must support this value
     41 of @var{version}.
     42 
     43 Implementations may also support other values of @var{version}, in
     44 which case they return a specifier for an environment containing
     45 appropriate bindings corresponding to the specified version of
     46 the report. If @var{version} is neither @code{5} nor another value
     47 supported by the implementation, an error is signaled.
     48 
     49 The effect of defining or assigning (through the use of @code{eval})
     50 an identifier bound in a @code{scheme-report-environment} (for example
     51 @code{car}) is unspecified.  Thus both the environment and the bindings
     52 it contains may be immutable.
     53 
     54 @end deffn
     55 
     56 @deffn {repl library procedure} interaction-environment
     57 
     58 This procedure returns a specifier for a mutable environment that
     59 contains an implementation-defined set of bindings, typically a
     60 superset of those exported by @code{(scheme base)}.  The intent is that
     61 this procedure will return the environment in which the implementation
     62 would evaluate expressions entered by the user into a REPL.
     63 
     64 @end deffn
     65 
     66 @deffn {eval library procedure} eval expr-or-def environment-specifier
     67 
     68 If @var{expr-or-def} is an expression, it is evaluated in the specified
     69 environment and its values are returned.  If it is a definition,
     70 the specified identifier(s) are defined in the specified environment,
     71 provided the environment is not immutable.  Implementations may extend
     72 @code{eval} to allow other objects.
     73 
     74 @lisp
     75 (eval '(* 7 3) (environment '(scheme base))) @result{}  21
     76 
     77 (let ((f (eval '(lambda (f x) (f x x))
     78                (null-environment 5))))
     79   (f + 10))
     80     @result{}  20
     81 (eval '(define foo 32)
     82       (environment '(scheme base)))
     83     @result{} @r{error is signaled}
     84 @end lisp
     85 
     86 @end deffn