theEnvironment
theEnvironment( [u_funobj] ) =>e_environment/nil
Description
(SKILL++ mode only) Returns the top level environment if called from a SKILL++ top-level. Returns the enclosing lexical environment if called within a SKILL++ function. Returns the associated environment if passed a SKILL++ function object. Otherwise returns nil.
-
In SKILL++, there is a unique top-level environment that implicitly encloses all other local environments. If you do not pass the optional argument, when you call
theEnvironmentfrom a SKILL++ top-level,theEnvironmentreturns this environment. TheschemeTopLevelEnvfunction also returns this environment. -
If you call
theEnvironmentfrom within a SKILL++ function and if you do not pass the optional argument,theEnvironmentreturns the enclosing lexical environment. -
If you are in debug mode, you can pass a closure to
theEnvironment. A closure is another term for a function object returned by evaluating a SKILL++lambdaexpression which abstractly, consists of two parts: -
If you call
theEnvironmentfrom a SKILL function and do not pass a closure, thentheEnvironmentfunction returnsnil.
Arguments
Value Returned
Examples
Returns the environment that the let expression establishes. The value of Z is an environment in which x is bound to 3. Each time you execute the above expression, it returns a different environment object, as you can tell by observing the print representation.
Z = let( ( x )
x = 3
theEnvironment()
) ; let
=> envobj:0x1e0060
Uses theEnvironment to illustrate that the variable initialization expressions in a let expression refer to the enclosing environment.
Z = let( (( x theEnvironment()))
x
)
=> envobj:0x2fc018
eq( schemeTopLevelEnv() Z ) => t
Uses theEnvironment to illustrate that the variable initialization expressions in a letrec expression refers to the letrec’s environment.
V = letrec( (( x theEnvironment()))
x
)
=> envobj:0x33506c
eq( schemeTopLevelEnv() V ) => nil
eq( V~>x V ) => t
Returns the environment that the nested let expressions establish. Notice that assigning it to the top-level variable W makes it persistent.
W = let( (( r 3 ) ( y 4 ))
let( (( z 5 ) ( v 6 ))
theEnvironment()
) ; let
) ; let
=> envobj:0x456030c
W~>r => 3
W~>z => 5
W~>?? => ((z(5) (v 6)) ((r 3) y(4)))
Returns a function object which, in turn, returns its local environment.
Q = letrec(
( ;; begin locals
( X 6 )
( self
lambda( ( )
theEnvironment()
) ; lambda
) ; self
) ;;; end of locals
self
) ; letrec
=> funobj:0x1e38b8
Q() => envobj:0x1e00e4
theEnvironment( Q ) => envobj:0x1e00e4 ;in debug mode only
Related Topics
Return to top