Example Lambda define 001
|
This example shows how Lambdas are defined using the define function and the
pvars special form.
Notes and Hints The scope of defined variables depends upon the current environment at the
time the define function is invoked. A variable defined at the top level will
have global scope. A variable defined within a Lambda will extend the pvars:
structure associated with the Lambda and will have scope limited to the Lambda. The scope of variables in nested Lambdas depends upon the following Lisp
compilation rules. Nested Lambdas do not share either their argument or their
temporary variables. The argument and the temporary variables are always limited
in scope to the immediate Lambda object. A nested Lambda both shares and extends the
persistent variables (pvars) of its parents. When a variable reference is
encountered, the Lisp compiler first searches the local Lambda's arguments for a
match, then the searches the local Lambda's temporary variables (vars)
for a match, finally searches the Lambda's extended persistent variables (pvars)
and then the (cvars) for a match. A referenced variable, without a match,
always refers to the global value of the variable. Search order for finding a variable: Av: The arguments
Structure object containing the Lambda's arguments. Tv: The vars:
Structure object containing the Lambda's temporary frame variables. Pv: The pvars:
Structure object containing the Lambda's persistent variables. Cv: The cvars:
Structure object containing the Lambda's persistent class variables. Rv: The regs:
Structure object containing the Lambda's register variables. Globals The global variables in the workspace.
(define (foo1 )
(define X 5)
(writeln "The value of X is " X))
Returns:
;; Initialize X with the value 5
(define (foo2 ) pvars:((X 5))
(writeln "The value of X is " X))
Returns:
Returns:
Returns:
Here are examples of the define function at work.
Lambda define 001 |
Here is the link to the current function used in this example.
Here are a number of links to other related functions.
deforphan(#void) | defmethod(#void) | defmacro(#void) | defun(#void) |
Here are the links to the data types of the arguments used in this example. Here are a number of links to examples having similar argument types.
Lambda
String
Analytic Information Server (AIS)AIS Component Systems
|