Selector Statements

 

Statements Overview

This chapter is a reference guide to the Selector statements. These statements contain the basic control flow operators for the Selector language. All of the basic building blocks of Selector are contained in its statements. Selector is case sensitive.

All Selector statements are lexical structures, which are understood only by the Selector parser. They are not understood by the system outside of the Selector parser, and they are not available nor are they understood by Lisp. All Selector statements have meaning only at parse time.

All Selector special forms are structures, which are understood only by the Selector compiler. Unlike Function objects, the Selector special forms are invalid outside of compilation, at run time.

Selector supports user defined global symbols, allowing the user to assign any valid Selector object to the newly created global symbol. User defined global symbols behave just like their built-in cousins; however, Selector even allows the user to redefine any of the built-in Selector special form symbols.

Binary Arithmetic Operators

Overview

Selector supports the basic binary and unary arithmetic operations: addition (+), subtraction (-), multiplication (*), division (/), protected division (#), and modulus (%).

Type

Statement

Syntax

operand1 binaryOperator operand2

Arguments


Arguments Explanation
Operand1 The first operand.
binaryOperator The binary operator. Must be one of:   +, -, *, /, #, %.
Operand2 The second operand.
RETURN The result of the binary operation.

When To Use

Use the binary operator statement to perform basic arithmetic operations on two numeric values, or to concatenate two string values.

Example1

These simple examples demonstrates the effect of the various binary operators.

a = 1 + 20;             //Returns 21

b = 30 - 5;              //Returns 25

c = 2 * 2.1;             //Returns 4.2

d = 100 / 10;          //Returns 10

e = 10 % 4;           //Returns 2  (the remainder)

Notes & Hints

The binary operator statement performs basic arithmetic operations on two numeric values, or concatenates two string values.

On a divsion by zero, the protected divide operator returns the highest possible number in the system if the sign of the numerator is negative or the lowest possible number in the system if the sign of the numerator is positive.

Unary Arithmetic Operators

Overview

Selector supports the basic unary arithmetic operations: increment (++), decrement (--), and negation (-).

Syntax: unaryOperator operand1

Type

Statement

Syntax

unaryOperator operand1

operand1 incrementOperator

operand1 decrementOperator

Arguments


Arguments Explanation
unaryOperator The unary operator. Must be one of:   ++, --, -.
Operand1 The first operand.
RETURN The result of the unary operation.

When To Use

Use the unary operator statement to perform basic arithmetic operations on a single numeric value.

Example1

These simple examples demonstrates the effect of the various unary operators.

var a = 100;

var b  = 100;

var c = 10;

var d = 10;

++a;     //Returns 101

--b;      //Returns 99

c++;    //Returns 11

d--;     //Returns 9

-a;      //Returns -101

Notes & Hints

The unary operator statement performs basic arithmetic operations on a single numeric value.

Assigment Operators

Overview

Selector assigns a value to a variable with the = (equal) operator. Another class of assignment operators perform math operations on the variable and saves the result in the same variable. They are +=, -=, *=, /=and %=. The += operator is shorthand for a=a + exp.

Type

Statement

Syntax

variable assignmentOperator expression

Arguments


Arguments Explanation
variable The variable to be assigned a new value.
assignmentOperator The assignment Operator. Must be one of:  =, +=, -=, *=, /=, %=.
expression If the assignmentOperator is (=), the expression may return any value. If the assignmentOperator is (+=, -=, *=, /=, or %=), then the expression must return a numeric value.
RETURN If the assignmentOperator is (=), the variable is set to the value of expression. If the assignmentOperator is (+=, -=, *=, /=, or %=), then the arithmetic operation is performed on the original variable and the expression.

When To Use

Use the assignment operator statement to assign a new value to a Selector variable.

Example1

This simple example demonstrates the effect of the simple assignment operator.

a = 3.14;         //Returns 3.14

Example2

This examples demonstrate the effects of the arithmetic assignment operators.

var a = 100;

var b  = 100;

var c = 10;

var d = 10;

a += 10;      //Returns 110

b -= 10;      //Returns 90

c *= 10;     //Returns 100

Notes & Hints

The assignment operator statement assigns a new value to a Selector variable.

bgmregress

The bgmregress command trains one of our proprietary basis grid regression Lambdas, on the specified numeric expression list. The bgmregress statement should be the ONLY statement in the Selector program, and returns the trained basis grid regression Lambda.

Syntax

bgmregress (numericExpression1,numericExpression2,numericExpression3,numericExpressionN);

bgmregress Mandatory keyword
numericExpression1 (Mandatory)Numeric expression.
numericExpression2 (Optional)Numeric expression.
numericExpression3 (Optional)Numeric expression.
numericExpression4 (Optional)Numeric expression.

Example1

bgmregress(exp(x4),x10);

This will train a basis grid regression Lambda on the numeric expressions: exp(x4) and x10.

Note: Inside the numericExpressions, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

child

Overview

The child function declaration creates a new Lambda object and assigns it to the specified persistent variable name childName of the parent Lambda parent. The child function declaration always returns the newly created object identifier of the new Lambda. The child Lambda is invoked using the parent.childName() syntax form.

Type

Statement

Syntax

child parent childName ([type] arg..) { cvardec pvardec vardec exp }

Arguments


Arguments Explanation
child

Mandatory keyword.

parent

Name of the parent class

childName

The name of the child Lambda (function)

([type] arg...)

A list of type hints (optional) and arguments separated by commas. If there are no arguments the parenthesis are still required. Note: The optional type hints can be one of the following: char, bool, int, float, or obj

cvardec

Optional declaration. If present, must be followed by a persistent class variable declaration. See cvar.

pvardec

Optional declaration. If present, must be followed by a persistent variable declaration. See pvar.

vardec

Optional declaration. If present, must be followed by a local variable declaration. See var.

exp

The Selector statements that form the Lambda

RETURN An Lambda object.

When To Use

Use the child statement to create a new Selector Lambda with a child relationship to a parent Lambda.

Example1

This simple example demonstrates the effect of the simple assignment operator.

function  foo(x)  {
		
		               pvar y;
		
		               y = x
		
		               return (y);
		
		               }
		
		
		
		               child foo sum (x)  {
		
		               var temp ;
		
		               temp = x +  y;
		
		               return ( temp );
		
		    }

We can invoke the parent and the child Lambda as follows:

foo(10);                          //Returns 10
		
		              foo.sum(3);                       //Returns 13
		
		              compareEQ(foo.Cv, foo.sum.Cv);    //Returns true
		
		              compareEQ(foo.Pv, foo.sum.Pv);    //Returns true

Notes & Hints

The child statement creates a new Selector Lambda with a child relationship to a parent Lambda. A Child Lambda inherits pvar and cvar structures from its parent Lambda.

class

Overview

The class statement declares a class and names all of its members. The class statement can also use to sub-class, i.e., create a class that inherits from another class and extend it.

Type

Statement

Syntax

class className {member1 ; member2 ... }

class className extends parentClass {member1 ; member2 ... }

Arguments


Arguments Explanation
class

Mandatory Keyword

className

The name of this class

extends

Optional Keyword. If present, it must be followed by an existing parent class.

{member1; member2; ...}

The names of the class members, where each name is separated by a semicolon

RETURN An class name.

When To Use

Use the class statement to create a new class or to extend and existing class through in heritance.

Example1

This simple example demonstrates the effect of the simple assignment operator.

class employee {Name; Address; Salary }
		
		              emp = new ('employee' , 'Name' ,"Tom Jones" , 'Address',  "200 Main Street, Small Town,  USA" )
		
		              display(emp.Name)

Example2

This simple example demonstrates the effect of the simple assignment operator.

class employee {Name; Address; Salary }
		
		              class manager extends 'employee' {Perks }
		
		              emp = new ('employee' , 'Name' ,"Tom Jones" , 'Address',  "200 Main Street, Small Town,  USA" )
		
		              mgr = new('manager', 'Name', "John Smith", 'Perks', "Special Parking Space")

Notes & Hints

The class statement creates a new class or to extend and existing class through in heritance.

Comparison Operators

The comparison operators are ==(equal) , !=(not equal) ,< (less than) , <=(less than or equal) , > (greater than), >=(greater than or equal) . The resulting value is a Boolean value of true if the relational operator results in a true comparison otherwise the resulting value is false. Selector performs type checking and type conversions, therefore the operands need not be the same type.

Syntax

(obj1 operator obj2)

obj1

First object to be compared

operator

Must be ==(equal), !=(not equal) ,< (less than) , <=(less than or equal) , > (greater than), >=(greater than or equal) .

obj2

Second object to be compared

Returns

Returns true if the comparison is true, false if the comparison is false

Example1

                 var a = true; //Returns True
		
                 (a == true ); //Returns  True  
		
                 ( 2 < 3);  //Returns  True
		
                 ( 2 > 3);  //Returns  False
            

Conditional Expression

A conditional expression is a shorthand version of the if-else statement. Besides having a shorter syntax, conditional expression always return a value, unlike the if statement.

Syntax

condition ? val1 : val2

condition

A Boolean expression

?

Mandatory operator

val1

The value to be returned if condition is true.

:

Mandatory operator

val2

The value to be returned if condition is false.

Returns

If the condition is true, val1 is returned, otherwise val2 is returned

Example1

a = 1;
		
		         X = (a >= 1) ? 1 : -1  ); // X will be set to 1

cvar

The cvar statement declares a persistent class variable within an Lambda. This means that the persistent class variable will have a scope for the life of the Lambda object. The class variable is created and initialized when the Lambda is instantiated and re-initialized each time the Lambda is invoked. Although Selector is a dynamically typed language, the cvar allows the programmer to optionally provide hints to the compiler by specifying a type for variable declarations. The supported types are: char, bool, int, float, and obj. Specifying a type of obj is equivalent to specifying no type information.

Syntax

cvar varName
cvar varName=init
cvar type varName
cvar type varName=init

cvar

Mandatory keyword

type obj char bool int float obj text string symbol bitvec fltvec pcdvec stc dir dic matrix nummat vec bitvec numvec intvec objvec
cvarName

The name of the persistent class variable

=init

Optional argument. If present, the compiler will assign the cvarName to the value in init.

Note: If type hints are supplied, the programmer must assure that no other types are saved in the variable. Note: Multiple variable declarations may be separated by commas as in: cvar x, int y, z;.

When To Use

Unlike a temporary variable (var) that is declared inside a function and which is only "alive" while the function is currently active, a cvar (persistent variable) is accessible, as long the Lambda object instance is active. The contents of the entire cvar structure is in LambdaName.Cv, where LambdaName is the name of the instance of the Lambda. The contents of a single cvar variable is LambdaName.Cv.memberName;

A persistent class variable (cvar) is analogous to a static variable in a C or C++ programming environment. It is created and initialized when the Lambda is instantiated and it is persistent, meaning the memory is not released as long as the Lambda is in memory. However, the cvar differs from the pvar in that it is always re-initialized on entry to the Lambda that encapsulates it.

Example1

function squareIt(x)  {
		
		    cvar float xx;
		
		    var y;
		
		    xx = x * x;
		
		    y = xx;
		
		    return (xx);
		
		    }
		
		
		
		    var result, int;
		
		    result = squareIt(10);
		
		    writeln(result); //displays "100"
		
		    writeln(squareIt.Cv.xx); //displays "100"		
		
		    writeln(squareIt.y); //error !Cannot find name: y in the PV structure of Lambda squareIt!

Example2

function foo  (x)  {
		
		         cvar z;
		
		         z = x;
		
		         return(z);
		
		         }
		
		
		
		         var z;
		
		         result = foo(7);
		
		         display(result);  //displays "7"
		
		         display(z);  //displays #void  (accesses the contents of the global variable)
		
		         display(foo.Cv.z);  //displays "7"

Notes and Hints

The scope of variables in nested Lambdas depends upon the following compilation rules: Nested Lambdas do not share either their arguments or their temporary variables. The argument and the temporary variables are always limited in scope to the immediate Lambda object. A nested Lambda shares the persistent variables (pvar) and the persistent class variables (cvar) of its parents. When a variable reference is encountered, the Selector compiler first searches the local Lambda's temporary variables (var), then the persistent variable structure (pvar), then the persistent class structure (cvar), and finally the global variables.

Also note: Any variable that is used without explicit declaration is automatically declared as a global variable. (This is true even if it is used inside a function definition).

ennregress

The ennregress command trains one of our evolutionary neural net regression Lambdas, on the specified numeric weight list. The ennregress statement should be the ONLY statement in the Selector program, and returns the trained neural net regression Lambda.

Syntax

ennregress (weightVector);

ennregress Mandatory keyword
weightVector Vector of hidden layer weights.

Example1

ennregress(#(obj| #(obj| #(num| 34.56 -23.5))));

This will train a neural net regression Lambda on the numeric hidden layer weight vector.

for

The for statement repeats a set of Selector statements until the specified condition is false.

Syntax

for ( initexp; cond; increxp ) { exp ... }

for

Mandatory keyword

Initexp;

Initializer expression. Usually resets an index to be used to determine loop control

cond;

An expression that returns a Boolean value. Usually tests the loop index to see if has reached a max number.

Increxp

Increment expression. Usually increments (or decrements) the loop index.

{expr...}

A set of Selector statements

Example1

var int a;
		
		         for (a = 1; a < 10; ++a ) { display(" ", a)}

This will display the following line in the console screen:

1  2  3  4  5  6  7  8  9  

friend

The friend statement creates a new Lambda object and assigns it to the specified persistent variable name friendName of the parent Lambda parent. The friend function declaration always returns the newly created Lambda object. The new friend Lambda is invoked by using the parent.friendName ()

Syntax

friend parent friendName ([type] arg..) { cvardec pvardec vardec exp}

friend

Mandatory keyword.

parent

Name of the parent class

friendName

The name of the friend Lambda (function)

([type] arg...)

A list of type hints (optional) and arguments separated by commas. If there are no arguments the parenthesis are still required. Note: The optional type hints can be one of the following: char, bool, int, float, or obj

cvardec

Optional declaration. If present, must be followed by a persistent class variable declaration. See cvar.

pvardec

Optional declaration. If present, must be followed by a persistent variable declaration. See pvar.

vardec

Optional declaration. If present, must be followed by a local variable declaration. See var.

exp

The Selector statements that form the Lambda

Returns

Lambda object identifier

Example1

function foo(x) {
pvar y=5, d;
d=x
return (d);
}

friend foo sum (x) {
pvar d=20 ;
var temp ;
temp=x + d + y;
return ( temp );
}

We can invoke the parent and friend Lambdas as follows:

foo(10); //Returns 10
		
	           	 foo.sum(3); //Returns 28
		
		         compareEQ(foo.Pv,  foo.sum.Cv); //Returns true
		
		         compareEQ(foo.Pv,  foo.sum.Pv); //Returns false

Notes and Hints

A friend Lambda has a different pvar structure than its parent Lambda, but the cvar structure of a friend Lambda is the pvar structure of its parent Lambda.

frmregress

The frmregress command trains a multivariate factor regression on the specified numeric expression list. The frmregress statement should be the ONLY statement in the Selector program, and returns the trained multivariate factor regression Lambda.

Syntax

frmregress(numericExpression1,numericExpression2,,...,numericExpressionN);

frmregress Mandatory keyword
numericExpression1 Numeric expression.
numericExpressionN Numeric expression.

Example1

frmregress(exp(x4),x10);

This will train a multivariate factor regression model on the numeric expressions: exp(x4) and x10.

Note: Inside the numericExpressions, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

function

A Selector function compiles into a first class Lambda object. It has the same footprint and is treated like any Lambda Object created by any compiler in the LambdaClient development environment.

Syntax

function name ([type] arg..) { cvardec pvardec vardec exp }
function ([type] arg..) { cvardec pvardec vardec exp }

function

Mandatory keyword.

name

(Optional) The name of the Lambda (function)

([type] arg...)

A list of type hints (optional) and arguments separated by commas. If there are no arguments the parenthesis are still required. Note: The optional type hints can be one of the following: char, bool, int, float, or obj

cvardec

Optional Argument. If present, must be followed by a persistent variable declaration. See cvar.

pvardec

Optional Argument. If present, must be followed by a persistent variable declaration. See pvar.

vardec

Optional Argument. If present, must be followed by a local variable declaration. See var.

exp

The Selector statements that form the Lambda

Returns

Lambda object identifier

Note: A function with no name will generate an unnamed function.

When To Use

The function statement defines the name of an Lambda, its arguments, and the statements that comprise the Lambda.

Example1

function foo (x) {
		
		         writeln( "The value of x is " , x);
		
		         }

To invoke:

foo(29);

Example2

function sayHello  ( ) {
		
		         writeln( "Hello World");
		
		          }

To invoke:

sayHello();

Function Invocation

Selector functions may be called by name or by Object Identifier. The function to be invoked must always have a set of parenthesis following the function name. If the function requires arguments, the arguments are passed as a comma separated list inside the parenthesis.

Syntax

name ()
name (arg ...)
Lambda.child ()
Lambda.friend ( arg ...)
class.method ()
class.method ( arg ...)

name

The name of the function to be invoked.

class.method

Alternate form of function name. Must be a method of a specified class

(arg...)

A list of arguments separated by commas. If there are no arguments the parenthesis are still required.

Returns

Lambda object identifier

Example1

foo (x) {
			
			         display( "The value of x is " , x);
			
			          }

To invoke:

foo (1998);

Example2

function  foo(x) {
			
			         pvar y;
			
			         y = x;
			
			         return (y);
			
			         }
			
			
			
		           	child foo sum (x) {
			
			        var temp;
			
			        temp = x +  y;
			
			        return ( temp );
			
			        }

We can invoke the parent and the child Lambda as follows:

foo(10);  //Returns 10
			
			         foo.sum(3);  //Returns 13

if

The if statement selects one of two expressions to evaluate based upon the value of a {test} expression. If the {cond} evaluates to True, then the expressions in the {thenClause} is evaluated.

If the else keyword is present and the {test} evaluates to false, then the expressions in the {elseClause} is evaluated.

The {test} and {thenClause} expressions are mandatory. The {else} expression is optional. The braces {} are also mandatory.

The {elseClause} may also be an if statement therefore creating a limitless number of conditions and conditional paths.

Syntax

if (test) { trueClause... }
if (test) { trueClause... } else { elseClause... }
if (test) { trueClause... } else if (test2) { exp ... }

test

An expression that returns a Boolean value. Must be enclosed in parenthesis.

thenClause

The expression to be executed if the cond clause returned True

else

Optional Keyword

elseClause

Optional expression. If the else keyword is present the elseClause must be present. The expression to be executed if the cond clause returned False

else if

If present, must be a valid if statement.

Returns

Returns the value of the expression evaluated. If no else clause is specified, the returned value is the result of the condition expression.

When To Use

The if statement is used whenever it is necessary to perform actions based on a condition

Example1

j=1
if ( j < 10 ) { k = 100;} else { k = -100;} //sets k to 100

Example2

	j = 2;
		
	  				if ( j < 10 )  { k = 100;} 
		
					else if ( j == 0)  {k = 10;}
		
					else if ( j == 1 ) {k = 100;} 
		
					else if ( j == 2 ) {k = 1000;} //sets k to 1000

Logical Operators

The logical operators are && (and) , || (or) , and ! (not) . The resulting value from a logical operation is a Boolean value. The && operator returns true if both operands are true, the || operator returns true if one or both operands are true, and the ! operator returns true if the operand is false, otherwise the ! operator returns false. Selector performs type checking and type conversions, therefore if the operands are not Boolean, the operands are converted to Boolean.

Syntax

(obj1 && obj2 )
(obj1 || obj2 )

obj1

First object to be compared

operator

Must be && (and) , || (or)

obj2

Second object to be compared

Returns

The && operator returns true if both operands are true, otherwise it returns false. The || operator returns true if one or both operands are true otherwise it returns false.


Syntax

(!obj1)

!

Logical not operator

obj1

Object to be negated

Returns

Returns true if the operand is false, otherwise the ! operator returns false.

Example1

	var a = true, k;
			
						if ( 2 < 3) && (a == true) {k = 1;} else {k = 2;} // sets k to 1   
			
						if ( 2 > 3) || (a == true) {k = 1;} else {k = 2;} // sets k to 1   
			
						if ( 2 > 3) && (!a) {k = 1;} else {k = 2;}// sets k to 2

method

The method statement defines a method to Selector class.

Syntax

method className methodName([type] arg...) { expr }

method

Mandatory keyword

className

Name of the parent class of the method

methodName

Name of this method.

([type] arg...)

A list of type hints (optional) and arguments separated by commas. If there are no arguments the parenthesis are still required. Note: The optional type hints can be one of the following: char, bool, int, float, or obj

{expr}

A set of Selector statements

Example1

	class employee {Name; Address; Salary }
		
					method employee updateSalary( this, newSalary) {
		
					this.Salary = newSalary;
		
					}
		
					emp = new ('employee', 'Name', "Tom Jones",  'Address',  "200 Main Street, Small Town,  USA" )
		
					emp.updateSalary(45000);
		
					writeln (emp.Name, "'s new salary is ", emp.Salary);
Note: In a method declaration the receiving object (this) is declared, but is not passed in the function invocation.
emp.updateSalary(45000); // This is correct
		
				emp.updateSalary(emp,45000); // This is incorrect

mvlregress

The mvlregress command trains a multivariate linear regression on the specified numeric expression list. The mvlregress statement should be the ONLY statement in the Selector program, and returns the trained multivariate linear regression Lambda.

Syntax

mvlregress(numericExpression1,numericExpression2,,...,numericExpressionN);

mvlregress Mandatory keyword
numericExpression1 Numeric expression.
numericExpressionN Numeric expression.

Example1

mvlregress(exp(x4),x10);

This will train a multivariate linear regression model on the numeric expressions: exp(x4) and x10.

Note: Inside the numericExpressions, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

new

The new function creates an instance of an object. The Lambda Information Server definition of an object is very specific. It is a memory resident container to store data, which is of variable length or is too large to fit in small fixed containers. The Analytic Information Server object Heap manager supports automated object resizing, garbage collection, and anti-fragmentation algorithms so that the user may concentrate on the analysis and modeling of data rather than on memory management.

The Selector compiler supports all of the Analytic Information Server objects. Each object is covered in detail in its own chapter in the Lambda Information Server Programmer's Guide.

Syntax

new ('objectType' )
new ('String' , value)
new ('Symbol' , value)
new ('Vector' , vecSubType, size)
new ('Vector', vecSubType, size, value)
new ('Structure', key, value)
new ('Structure', key, value ... . cdr )
new ('Dictionary', key, value)
new ('Directory', key, value)
new ('ObjectRepository', filename, 'key', code, 'buffer', count)

new

Mandatory keyword

objectType

Must be 'String', 'Symbol', 'Vector', 'Structure' , 'Dictionary', 'Directory', 'ObjectRepository'

value

Optional Argument. If present, must be a constant of type objectType.

vecSubType

Optional argument, but if present must only be used with objectType, Vector. Valid vecSubtypes are

'normal'

'bit'

'integer'

'float'

'number'

'small'

'object'

'pcode'.

If omitted, the default is normal vector.

size

Optional argument, but if present must only be used with objectType, Vector. It must be an integer representing the number of items the Vector will store.

key, value

Optional arguments to Structure, Dictionary, and Directory, but must appear in pairs. There may be an arbitrary number of key, value pairs.

. cdr

Optional Argument to Structure only. If present, it must be a constant that will be assigned to the cdr (tail) of a structure.

filename

If objectType is ObjectRepository, filename is a mandatory field which names the database archive file to be associated with the ObjectRepository. If no such file exists, a new database archive file will be created.

'clear'

If objectType is ObjectRepository, 'clear' is an optional keyword. If present, the database archive file will be cleared immediately before any further processing. If no such file exists, a new database archive file will be created.

'key', code

If objectType is ObjectRepository, 'key' is an optional keyword. If present and it must followed by a number. See ObjectRepository in the Programmer's Guide for more detail.

'buffer',count

If objectType is ObjectRepository, 'buffer' is an optional keyword. If the key word 'buffer' is present, the numeric buffered object count must follow. See ObjectRepository in the Programmer's Guide for more detail.

Returns

The new function will return an object identifier for the type specified in objectType .

Example1

Selector Syntax Lisp Syntax
new ('String', "John") (new String: "John")
new ('Symbol' , "Donald") (new Symbol: "Donald")
new ('Vector', 3, 11, 12, 99) (new Vector: 3 11 12 99)
new ('Vector' , 'bit', 5, 1 ) (new Vector: bit: 5 1)
new ('Structure', 'X', 22, 'Y', 34, ' .', 3) (new Structure: X: 22 Y: 34 . 3)
new ('Dictionary' , 'Name', "John Doe", 'Age', 30) (new Dictionary: Name: "John Doe" Age: 30)
new ('Directory' , 1, "New Year's Day", 2, "Valentine's Day" ) (new Directory: 1 "New Year's Day" 2 "Valentine's Day" )
new ( 'ObjectRepository', "myarchive.odb") (new ObjectRepository: "myarchive.odb")

orphan

The orphan statement creates a new Lambda object and assigns it to the specified persistent variable name orphanName of the parent Lambda parent. The orphan function declaration always returns the newly created Lambda object. The new orphan Lambda is invoked by using the parent.orphanName () syntax form.

Syntax

orphan parent orphanName ([type] arg..) { cvardec pvardec vardec exp}

orphan

Mandatory keyword.

parent

Name of the parent class

orphanName

The name of the orphan Lambda (function)

([type] arg...)

A list of type hints (optional) and arguments separated by commas. If there are no arguments the parenthesis are still required. Note: The optional type hints can be one of the following: char, bool, int, float, or obj

cvardec

Optional declaration. If present, must be followed by a persistent class variable declaration. See cvar.

pvardec

Optional declaration. If present, must be followed by a persistent variable declaration. See pvar.

vardec

Optional declaration. If present, must be followed by a local variable declaration. See var.

exp

The Selector statements that form the Lambda

Returns

Lambda object identifier

Example1

  	 function  foo(x) {
		
		   			 pvar y = 5; pvar d =30;
		
		   			 var temp ;
		
		   			 temp = x + d + y;
		
		   			 return ( temp );
		
		   			 }
		
		
		
					orphan foo  sum (x) {
		
		   		    pvar d = 20 ; 
		
		  		    cvar e = 100 ; 
		
		   			var temp ;
		
		   		    temp = x + d + y;
		
		   		   return ( temp );
		
		    		}

We can invoke the parent and orphan Lambdas as follows:

 	y = 10; //declare a global variable
		
				 	foo(10); //Returns 45
		
					foo.sum(10); //Returns 40 (uses the value of global  y)
		
					compareEQ(foo.Cv,  foo.sum.Cv); //Returns false
		
					compareEQ(foo.Pv,  foo.sum.Pv); //Returns false

Notes and Hints

An orphan Lambda is a member of its parent's pvar structure. Therefore, the parent knows about the orphan. However, the orphan Lambda has a different pvar structure than its parent Lambda, and a different cvar structure than its parent Lambda. Therefore, an orphan Lambda knows nothing of its parent Lambda.

pvar

The pvar statement declares a persistent variable within an Lambda. This means that the persistent class variable will have a scope for the life of the Lambda object. The persistent variable is created and initialized when the Lambda is instantiated and not re-initialized each time the Lambda is invoked. Although Selector is a dynamically typed language, the pvar allows the programmer to optionally provide hints to the compiler by specifying a type for variable declarations. The supported types are: char, bool, int, float, and obj. Specifying a type of obj is equivalent to specifying no type information.

Note: If type hints are supplied, the programmer must assure that no other types are saved in the variable.

Syntax

pvar varName
pvar varName = init
pvar type varName
pvar type varName = init

pvar

Mandatory keyword

type obj char bool int float obj text string symbol bitvec fltvec pcdvec stc dir dic matrix nummat vec bitvec numvec intvec objvec
pvarName

The name of the persistent variable

=init

Optional argument. If present, the compiler will assign the pvarName to the value in init.

When To Use

Unlike a var statement that is declared inside a function, the variables are only "alive" while the function is currently active. A pvar (persistent variable) is accessible, as long the Lambda object instance is active. The contents of the pvar structure is in LambdaName.Pv, where LambdaName is the name of the instance of the Lambda.

A persistent variable (pvar) is analogous to a static variable in a C or C++ programming environment. . It created and initialized when the Lambda is instantiated.

Unlike temporary variables (var), which are always allocated and initialized upon entry to a function and released upon exit, a pvar is initialized once and the memory allocated is fixed until the application ends.

Example1

	function squareIt  (x)  {
		
		    		pvar xx;
		
		    		var y;
		
		   			xx = x * x;
		
		    		y = xx;
		
		    		return (xx);
		
		    		}
		
		
		
					var result;
		
					result = squareIt (10);
		
					writeln(result);  //displays "100"
		
					writeln(squareIt.xx);  //displays "100"
		
					writeln(squareIt.y); //error !Cannot find name: y in the PV structure of Lambda squareIt!

Notes and Hints

The scope of variables in nested Lambdas depends upon the following compilation rules: Nested Lambdas do not share either their arguments or their temporary variables. The argument and the temporary variables are always limited in scope to the immediate Lambda object. A nested Lambda shares the persistent variables (pvar) and the persistent class variables (cvar) of its parents. When a variable reference is encountered, the Selector compiler first searches the local Lambda's temporary variables (var), then the persistent variable structure (pvar), then the persistent class structure (cvar), and finally the global variables.

Also note: Any variable that is used without explicit declaration is automatically declared as a global variable. (This is true even if it is used inside a function definition).

reg

The reg statement declares a register variable inside a Selector program. If a reg statement appears outside a function definition, the variable declaration generates an error message.

The reg statement declares a register variable within an Lambda. This means that the register variable will have a scope for this invocation of the Lambda object. The register variable is created and initialized each time the Lambda is invoked. Although Selector is a dynamically typed language, the reg allows the programmer to optionally provide hints to the compiler by specifying a type for register declarations. The supported types are: int and float. Specifying a type of int is equivalent to specifying no type information.

Note: If type hints are supplied, the programmer must assure that no other types are saved in the variable.

Syntax

reg varName
reg varName=init|
reg type varName
reg type varName=init

reg

Mandatory keyword

type int float
varName

The name of the register variable

=init

Optional argument. If present, the compiler will assign the varName to the value in init.

When To Use

It is necessary to explicitly declare register variables inside a function using the reg statement. The register variable structure, LambdaName.Rv, (where LambdaName is the name of the instance of the Lambda) is accessible.

Register variables are always allocated and initialized upon entry to a function and released upon exit.

Example1

	function zoo  (x)  {
		
		    			reg int m;
		
		    			m = x;
		
		    			writeln(m);
		
		    			return (m);
		
		    			}
		
		
		
						var m = 99;
		
						result = zoo(7); //displays "7"  (accesses the contents of the local variable)
		
						writeln(m);  //displays "99"  (accesses the contents of the global variable)
		
						writeln(zoo.m); //error--!Cannot find name: m in the PV structure of Lambda zoo!

regress

The regress command trains a simple linear regression on the specified numeric expression. The regress statement should be the ONLY statement in the Selector program, and returns the trained simple linear regression Lambda.

Syntax

regress numericExpression;

regress Mandatory keyword
numericExpression Numeric expression.

Example1

regress exp(x4)*x10;

This will train a simple linear regression model on the numeric expression: exp(x4)*x10.

Note: Inside the numericExpression, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

return

The return statement exits the current function passes a single value to the caller.

Syntax

return ( value )

value

Any expression that returns a value. May be embedded in parenthesis

Returns

Immediately evaluates the expression, returns the value, and resume execution of the caller function

When To Use

The return statement is used to leave the current function and return to the caller with a return value.

Example1

	
                function foo  (x)  {

                var m;

                m = x * 2;

                return (m); // the value of m is returned to the caller

                }



                result = foo(7); //result will receive the value of 14
        

score

The score statement performs a set of scoring operations on the current row manager. The score statement must be followed by a single command. The score statement supports commands for averaging and totalling rows from the The score statement does not alter the current record view.

Syntax

score command;

score Keyword (optional)
command score statement command (mandatory).

Syntax

score expression;

score Keyword (mandatory)
expression Any valid javaFilter expression including imbedded score statement commands (mandatory).

Syntax

score variable=command;

score Keyword (optional)
variable A variable name to receive the finished score.
= The javaFilter assignment operator.
command score statement command (mandatory).

Notes and Hints

Note1: The score statement generates code which assumes that the variable named, XT, contains the ESM row manager which is to be operated upon.

Note2: The score statement may be used as a stand alone statement in a global declaration or inside an existing function. A stand alone select statement is automatically enclosed in the following universal parse tree lambda:

(lambda (XT) (begin ...score statement block...))

Score Command: average

The average command averages a numeric expression over each row in the current row manager.

Syntax

average expression

average Mandatory keyword
expression Numeric expression.

Example1

score average x3;

This will return the average of x3 for the current record view.

Note: Inside the score expression, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

Score Command: averageForAll

The averageForAll command averages a numeric expression over ALL rows in the current row manager.

Syntax

averageForAll expression

averageForAll Mandatory keyword
expression Numeric expression.

Example1

score averageForAll x10;

This will return the average of x10 for all rows in the current row manager.

Note: Inside the score expression, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

Score Command: extract

The extract command extracts single or multiple columns of data from the current record view.

Syntax

extract extractExpression

extract Mandatory keyword
extractExpression Single or multiple column extraction expression.

extract : spineVectorType : extractExpression

extract Mandatory keyword
spineVectorType The type of the spine vector for this extraction: Integer, Number, Object, or Word (defaults to Object:).
extractExpression Single or multiple column extraction expression.

Example1

score extract new('Vector','Number',2,(x1/x2),sin(x4));

This will extract two columns of data, as specified, from all rows in the current record view. The results will be returned as an Object Vector (the missing spineVectorType argument defaults to Object) with exactly as many entries as there are rows in the current record view.

Example2

score extract : Number : sin(x4);

This will extract one columns of data, as specified, from all rows in the current record view. The results will be returned as a Number Vector with exactly as many entries as there are rows in the current record view.

Note: Inside the extractExpression, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

Score Command: total

The total command totals a numeric expression over each row in the current record view.

Syntax

total expression

total Mandatory keyword
expression Numeric expression.

Example1

score total x5;

This will return the total of x5 for the current record view.

Note: Inside the score expression, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

Score Command: totalForAll

The totalForAll command totals a numeric expression over ALL rows in the current row manager.

Syntax

totalForAll expression

totalForAll Mandatory keyword
expression Numeric expression.

Example1

score totalForAll (x4 / x2);

This will return the total of (x4 / x2) for all records in the current row manager.

Note: Inside the score expression, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

Select

The select statement performs a set of selection operations on the XT argument (the row manager Lambda containing the set of Number Vectors for the current time period). The select statement may be followed by a single command or by multiple commands. The select statement supports commands for sorting and selecting rows from the current record view (the currently selected rows). The select command only alters the current record view.

Syntax

select command1; ... commandN;

select Keyword (optional)
Command1; select statement command (mandatory).
CommandN; select statement command (optional).

Notes and Hints

Note1: All the commands of a single select statement are grouped together into a single block. This is true regardless of whether or not the select keyword is present, and regardless of whether or not the multiple select commands are enclosed in braces.

Note2: The select statement generates code which assumes that the variable named, XT, contains the ESM row manager Lambda which is to be operated upon.

Note3: The select statement may be used as a stand alone statement in a global declaration or inside an existing function. A stand alone select statement is automatically enclosed in the following universal parse tree lambda:
(lambda (XT) (begin ...select statement block...) XT)

Note4: The select statement always automatically converts any element name symbol into a row index reference.

Select Command: all

The all command performs a selection operation on the current recordview.

Syntax

all selectExpression

all Mandatory keyword
selectExpression Select expression.

Example1

select all x4 > 10000;

This will delete all rows from the current record view where x4 is not greater than 10000.

Example2

select all (x4/sin(x2)) > .54;

This will delete all rows from the current record view where (x4/sin(x2)) is not greater than .54.

Note: Inside the selectExpression, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

Select Command: bottom

The bottom command performs a sort on the current row manager, followed by a deletion operation on the current row manager.

Syntax

bottom sortExpression cutoff

bottom Mandatory keyword
sortExpression Sort expression.
cutoff Cut off absolute number or percent.

Example1

select bottom (x10 * x1) 100;

This will delete all rows from the current record view which are not in the top 100 rows of all (x10 * x1).

Note: Inside the selectExpression, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

Select Command: highest

The highest command performs a sort on the current row manager, followed by a deletion operation on the current row manager.

Syntax

highest sortExpression cutoff

highest Mandatory keyword
sortExpression Sort expression.
cutoff Cut off absolute number or percent.

Example1

select highest x4 10%;

This will delete all rows from the current record view which are not in the top 10% of all x4.

Note: Inside the selectExpression, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

Select Command: restore

The restore command restores the backup view of the current table cursor.

Syntax

restore

restore Mandatory keyword

Example1

select restore;

This will restore the all rows view of the current row manager.

Select Command: run

The run command performs a select on the current row manager.

Syntax

run functionCall

run Mandatory keyword
functionCall A Selector function call expression to a specified select Lambda.

Example1

select run "mySelector";

This will run the "mySelector" Selector Lambda, in the current project, on the current record view.

Select Command: slice

The slice command performs an ascending sort on the current row manager, followed by a tile operation on the current row manager.

Syntax

slice sortExpression tileIndex of tileCount

slice Mandatory keyword
sortExpression Sort expression.
tileIndex The index of the tile to show.
of Mandatory keyword.
tileCount The number of tiles.

Example1

select slice (x21 * x2) 42 of 100;

This will retain all rows from the current record view which are in the 42 percentile of (x21 * x2).

Note: Inside the selectExpression, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

Select Command: sort

The sort command performs a sort on the current row manager.

Syntax

sort [direction] sortExpression

sort Mandatory keyword
direction Optional Sort direction: up or down (optional). If sort direction is omitted, the direction is assumed to be up.
sortExpression Mandatory Sort expression.

Example1

select sort down x3;

This will sort all rows in the current record view in descending order by x3.

Note: Inside the selectExpression, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

Select Command: top

The top command performs a sort on the current row manager, followed by a deletion operation on the current row manager.

Syntax

top sortExpression cutoff

top Mandatory keyword
sortExpression Sort expression.
cutoff Cut off absolute number or percent.

Example1

select top x4 10%;

This will delete all rows from the current record view which are not in the top 10% of all x4.

Note: Inside the selectExpression, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

Statement Blocks

An arbitrary number of Selector statements may be grouped logically by embedding the statements in braces { exp ...}. A statement block such as this may be placed in any position where a single statement is required. Multiple statements in Selector may be written on a single line as long as a semicolon terminates each statement.

Syntax

{exp ...}

exp ...

Any number of expressions to be evaluated

When To Use

A statement block may be placed in any position where a single statement is required.

Example1

	j = 1;

				if ( j < 10 ) { k = 100; writeln(k);} else { k = -100; writeln(k);} 

svmregress

The svmregress command trains a support vector regression, with a cubic kernel, on the specified numeric expression list. The svmregress statement should be the ONLY statement in the Selector program, and returns the trained support vector regression Lambda.

Syntax

svmregress;

svmregress Mandatory keyword
This form of the svmregress statement is equivalent to regressing on a list of all column names.

svmregress(numericExpression1,numericExpression2,,...,numericExpressionN);

svmregress Mandatory keyword
numericExpression1 Numeric expression.
numericExpressionN Numeric expression.

Example1

svmregress(exp(x4),x10);

This will train a support vector regression model, with a cubic kernel, on the numeric expressions: exp(x4) and x10.

Note: Inside the numericExpressions, the name XT refers to the ESM row manager Lambda input argument. The name xv refers to the currently focused record. The names xtime, y, and x1 thru xm, refer to elements within the currently focused record.

var

The var statement declares a temporary variable inside a Selector program. The location of the var statement determines the scope the variable. If a var statement appears inside a function definition, the variable is considered local to that function only. If a var statement appears outside a function definition, the variable has global scope.

The var statement declares a temporary variable within an Lambda. This means that the temporary variable will have a scope for this invocation of the Lambda object. The temporary variable is created and initialized each time the Lambda is invoked. Although Selector is a dynamically typed language, the var allows the programmer to optionally provide hints to the compiler by specifying a type for variable declarations. The supported types are: char, bool, int, float, and obj. Specifying a type of obj is equivalent to specifying no type information.

Note: If type hints are supplied, the programmer must assure that no other types are saved in the variable.

Syntax

var varName
var varName=init|
var type varName
var type varName=init

var

Mandatory keyword

type obj char bool int float obj text string symbol bitvec fltvec pcdvec stc dir dic matrix nummat vec bitvec numvec intvec objvec
varName

The name of the temporary variable

=init

Optional argument. If present, the compiler will assign the varName to the value in init.

When To Use

Since global variables are automatically declared in the LambdaClient environment, it is unnecessary declare global variables. However, it is necessary to explicitly declare temporary variables inside a function using the var statement. The temporary variable structure, LambdaName.Tv, (where LambdaName is the name of the instance of the Lambda) is accessible, as long the Lambda object instance is active.

Temporary variables are always allocated and initialized upon entry to a function and released upon exit.

Example1

	function zoo  (x)  {

    			var m;

    			m = x;

    			writeln(m);

    			return (m);

    			}



				var m = 99;

				result = zoo(7); //displays "7"  (accesses the contents of the local variable)

				writeln(m);  //displays "99"  (accesses the contents of the global variable)

				writeln(zoo.m); //error--!Cannot find name: m in the PV structure of Lambda zoo!

Notes and Hints

The scope of variables in nested Lambdas depends upon the following compilation rules: Nested Lambdas do not share either their arguments or their temporary variables. The argument and the temporary variables are always limited in scope to the immediate Lambda object. A nested Lambda shares the persistent variables (pvar) and the persistent class variables (cvar) of its parents. When a variable reference is encountered, the Selector compiler first searches the local Lambda's temporary variables (var), then the persistent variable structure (pvar), then the persistent class structure (cvar), and finally the global variables.

Also note: Any variable that is used without explicit declaration is automatically declared as a global variable. (This is true even if it is used inside a function definition).

while

The while statement repeats a set of Selector statements until its condition is false.

Syntax

while (test) { expr }

while

Mandatory keyword

(test)

An expression that returns a Boolean value

{expr}

A set of Selector statements

Example1

	var int a = 1;

				while (a < 10)   { display (" ", a)  ++a }		

This will display the following line in the console screen:

1  2  3  4  5  6  7  8  9