Example Lambda define 001

 

 

Description

This example shows how Lambdas are defined using the define function and the pvars special form.

 

Details

The following are two separate forms.

         (define  (foo1 )
         (define  X  5)
         (writeln "The value of X is " X))

        
Returns: #<Lambda 123456 >
        ;; Initialize X with the value 5
        (define  (foo2 ) pvars:((X  5)) 
        (writeln "The value of X is " X)) 
        
Returns: #<Lambda 234567>
(foo1) Returns: The value of X is 5
(foo2) Returns: The value of X is 5

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.

 

Related Examples

Here are examples of the define function at work.

Lambda define 001

 

Function Links

Here is the link to the current function used in this example.

define

Here are a number of links to other related functions.

deforphan(#void) defmethod(#void) defmacro(#void) defun(#void)

 

Argument Types

Here are the links to the data types of the arguments used in this example.

Lambda String

Here are a number of links to examples having similar argument types.

BitVector isType 020 BitVector ref 027 Boolean isType 011 ByteVector isCharAlphabetic 003
ByteVector isCharAlphanumeric 003 ByteVector isCharLowercase 003 ByteVector isCharName 003 ByteVector isCharNumeric 003
ByteVector isCharUppercase 003 ByteVector isCharWhitespace 003 Character isType 012 Context debug 001
Context debugBrowsableProcs 001 Context disassemble 001 Context globalBinding 001 Context inspect 001
Date hour 001 Date isType 014 Date julian 001 Date minute 001
Date month 001 Date second 001 Date time 001 Date time 002
Date year 001 Dictionary isDictionary 001 Dictionary isType 006 Dictionary new 004
Directory isType 007 Directory new 005 Directory ref 010 Directory ref 012
Error error 001 Error errorTrap 001 Error isError 001 Error onError 001
FileIO closeLog 001 FltVector isType 016 FltVector ref 022 Function isType 015
IntVector isType 017 IntVector ref 023 Lambda argCount 001 Lambda argFetch 001
Lambda balance 001 Lambda callcc 001 Lambda compare 008 Lambda compareEQ 008
Lambda compareGE 008 Lambda compareGT 008 Lambda compareLT 008 Lambda compareNE 004
Lambda compile 001 Lambda copy 008 Lambda debug 001 Lambda debugBrowsableProcs 001
Lambda defchild 001 Lambda define 001 Lambda define(macro) 001 Lambda defmacro 001
Lambda defmacro 002 Lambda deforphan 001 Lambda defriend 001 Lambda defun 001
Lambda defun 002 Lambda disassemble 001 Lambda eval 001 Lambda exportTab 001
Lambda globalBinding 001 Lambda importTab 001 Lambda inspect 001 Lambda isLambda 001
Lambda lambda 001 Lambda makeLambda 001 Lambda myself 001 Lambda new 001
Lambda new 002 Lambda new 003 Lambda onError 001 Lambda ref 017
Lambda send 008 Lambda send 009 Lambda setq 015 Lambda type 011
Matrix isType 009 Matrix ref 015 Matrix ref 016 NumMatrix isType 022
NumMatrix ref 035 NumVector isType 018 NumVector ref 024 Number isType 013
ObjVector isType 019 ObjVector ref 025 ObjectRepository detachLibrarian 001 ObjectRepository refLibrarian 001
PcodeVector ref 026 ShortVector isType 018 ShortVector ref 024 String addMethod 001
String append 001 String append 002 String clean 001 String code 001
String compare 001 String compareEQ 001 String compareGE 001 String compareGT 001
String compareLE 001 String compareLT 001 String compareNE 001 String comparison functions 001
String defMethod 001 String defMethod 002 String downcase 001 String fileRead 001
String fileRead 002 String fileReadRecord 001 String fileWrite 001 String find 001
String find 002 String hashString 001 String isChar 001 String isCharAlphabetic 001
String isCharAlphanumeric 001 String isCharLowercase 001 String isCharName 001 String isCharNumeric 001
String isCharUppercase 001 String isCharWhitespace 001 String isEqual 001 String isEqual 002
String isObject 001 String isString 001 String isText 001 String isType 001
String isType 002 String isType 003 String left 001 String length 001
String length 002 String methodsOf 001 String methodsOf 002 String methodsOf 003
String mid 001 String new 001 String parse 001 String ref 001
String ref 002 String replace 001 String rept 001 String right 001
String send 001 String sizeof 001 String string 001 String string 002
String string 003 String stringCiEQ 001 String stringCiGE 001 String stringCiGT 001
String stringCiLE 001 String stringCiLT 001 String stringCiNE 001 String stringFill 001
String stringToBVector 001 String stringToBVector 002 String stringToBVector 003 String stringToVector 001
String stringToVector 002 String stringToVector 003 String stringToVector 004 String substitute 001
String substitute 002 String substring 001 String substring 002 String substringCiEQ 001
String substringCiGE 001 String substringCiGT 001 String substringCiLE 001 String substringCiLT 001
String substringCiNE 001 String text 001 String trim 001 String type 001
String upcase 001 String upcase 002 String upcase 003 Structure apply 002
Structure ref 004 Structure setq 003 Structure setq 004 Structure setq 005
Structure setq 006 Symbol *< 001 Symbol +< 001 Symbol -< 001
Symbol /< 001 Symbol isCharAlphabetic 002 Symbol isCharAlphanumeric 002 Symbol isCharLowercase 002
Symbol isCharName 002 Symbol isCharNumeric 002 Symbol isCharUppercase 002 Symbol isCharWhitespace 002
Symbol isObject 002 Symbol isSymbol 001 Symbol isType 004 Symbol length 003
Symbol makeQuotedSymbol 001 Symbol send 002 Symbol sizeof 002 Symbol symbol 001
Symbol symbol 002 Symbol type 002 Vector isType 008 Vector ref 013
Vector ref 014 Void isType 010 Void ref 017 substringEQ 001
substringFill 001 substringGE 001 substringGT 001 substringLE 001
substringLT 001 substringNE 001

Analytic Information Server (AIS)

AIS Component Systems

  • Smartbase Engine
  • QT C++ Libraries
  • MySQL Relational Database
  • AIS Lisp Libraries
  • Rapid Analytic Demo IDE