Product Documentation
Cadence SKILL Language Reference
Product Version IC23.1, November 2023

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.

Arguments

u_funobj

Optional argument. Should be a SKILL++ closure.

Value Returned

nil

Returned when called from a SKILL function and you do not pass a SKILL++ closure as the optional argument.

e_environment

Either the top-level environment, or the enclosing environment, or the closure’s environment.

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

Core Functions


Return to top
 ⠀
X