JavaScript Statements

 

Statements Overview

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

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

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

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

The Analytic Information Server dialect of javaScript is case sensitive.

Binary Arithmetic Operators

Overview

javaScript 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

javaScript 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

javaScript 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 javaScript 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 javaScript variable.

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 javaScript statements that form the Lambda

RETURN An Lambda object.

When To Use

Use the child statement to create a new javaScript 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 javaScript 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. javaScript 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 javaScript 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
Syntax: cvar varName=init
Syntax: cvar type varName
Syntax: 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 javaScript 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).

filter

The filter statement performs a set of filter operations on the dataMineLib.currentTable cursor. The filter statement may be followed by a single command or by multiple commands. The filter statement supports commands for sorting and deleting rows from the current view index. The filter command only alters the current table view. The backup table index is not altered by the filter command.
Syntax: filter command1; ?? commandN;

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

Notes and Hints

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

Note2: The filter statement generates code which assumes that the variable named, cursor, contains the dataMineLib cursor which is to be filtered.

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

Note4: The filter statement always automatically converts any name symbol into a row field reference.

Filter Command: all

The all command performs a deletion operation on the current table cursor. The backup table view is not effected.
Syntax: all filterexpression

all Mandatory keyword
filterexpression Filter expression.

Example1

filter all Sales > 10000;

This will delete all rows from the current table view where Sales are not greater than 10000. Any rows, where Sales are #void, will be eliminated from the current table view. The backup table view will not be altered.

Syntax: all old portfolio

all Mandatory keyword
old Mandatory keyword
portfolio Mandatory keyword

Example2

filter all old portfolio;

This form of the all command, will delete all rows from the current table view except those stocks contained in the previous portfolio. If the current table view is not empty, all remaining rows will have a Notes.Ownership element equal to the percent of the previous portfolio allocated to the specified stock. A positive ownership percent indicates a long position. A negative ownership percent is invalid as shorting is not allowed.

Note: This form of the all command can only be invoked within a Stock Weekly Summary Training window and then only during a fundWizard blind-forward-testing run.

Syntax: all portfolio

all Mandatory keyword
portfolio Mandatory keyword

Example2

filter all portfolio;

This form of the all command, will delete all rows from the current table view except those stocks contained in the current portfolio. If the current table view is not empty, all remaining rows will have a Notes.Ownership element equal to the percent of the previous portfolio allocated to the specified stock. A positive ownership percent indicates a long position. A negative ownership percent is invalid as shorting is not allowed.

Note: This form of the all command can only be invoked within a Stock Weekly Summary Training window and then only during a fundWizard blind-forward-testing run.

Syntax: all buy percent

all Mandatory keyword
buy Mandatory keyword
percent fractional ownership desired

Example3

filter all buy 10%;

This form of the all command, will set the Notes.Ownership element, of all existing rows, to the specified ownership percentage divided by the number of stocks. The current table view will not be otherwise altered. If the current table view is not empty, all existing rows will have a Notes.Ownership element equal to the specified ownership percent for the specified stock. A positive ownership percent indicates a long position. A negative ownership percent is invalid as shorting is not allowed.

Note: This form of the all command can only be invoked within a Stock Weekly Summary Training window and then only during a fundWizard blind-forward-testing run.

Syntax: all sell percent

all Mandatory keyword
sell Mandatory keyword
percent fraction of current ownership desired sold

Example4

filter all sell 100%;

This form of the all command, will sell the specified percent of current ownership, of all stocks in the current view. This command, will subtract from the Notes.Ownership element, of all current rows, the current ownership times the specified sales percentage. The current table view will not be otherwise altered. A positive ownership percent indicates a long position. A negative ownership percent is invalid as shorting is not allowed.

Note: This form of the all command can only be invoked within a Stock Weekly Summary Training window and then only during a fundWizard blind-forward-testing run.

Notes and Hints

Any names will be treated as table row field references UNLESS previously defined in var, reg, pvar, cvar, or argument list declarations.

Filter Command: bottom

The bottom command performs a sort on the current table cursor, followed by a deletion operation on the current table cursor.
Syntax: bottom sortexpression cutoff

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

Example1

filter bottom Sales * Price 100;

This will delete all rows from the current table view which are not in the top 100 rows of all (Sales * Price). Any rows, where Sales or Price are #void, will be eliminated from the current table view. The backup table view will not be altered.

Notes and Hints

Any names will be treated as table row field references.

Filter Command: check

The check command performs a deletion operation on the current table cursor.
Syntax: check name1 ? nameN

check Mandatory keyword
name1 Field name (mandatory).
nameN Field name (optional).

Example1

filter check Sales Price;

This will delete all rows from the current table view where either Sales or Price are #void. The backup table view will not be altered.

Notes and Hints

Any names will be treated as table row field references.

Filter Command: checkoff

The checkoff command turns off automatic field checking for the whole filter statement, including any commands which came before the checkoff command. (also the command nocheck can be used as a synonym for checkoff).
Syntax: checkoff

checkoff Mandatory keyword

Example1

filter checkoff; sort Sales;

This will sort all rows from the current table in ascending order by Sales. Even rows where Sales are #void will be included in the sort. The backup table view will not be altered.

Notes and Hints

Any names will be treated as table row field references.

Filter Command: omit

The omit command performs a deletion operation on the current table cursor. The current view of the table is permanently altered, and the back up view of the table is permanently altered. The omit command includes an implied checkoff command.
Syntax: omit filterexpression

omit Mandatory keyword
filterexpression Filter expression.

Example1

filter omit Sales > 10000;

 

This will delete all rows from the current table view where Sales are greater than 10000. The current table view will be altered. The backup table view will be permanently altered.

Notes and Hints

Any names will be treated as table row field references.

Filter Command: restore

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

restore Mandatory keyword

Example1

filter restore;

This will restore the backup view of the current table cursor. The backup table view will not be altered.

Notes and Hints

Any names will be treated as table row field references.

Filter Command: run

The run command performs a filter on the current table cursor.
Syntax: run nameString

run Mandatory keyword
nameString The name of the filter, in the current project, to run on the table cursor.

Syntax: run functionCall

run Mandatory keyword
functionCall A javaScript function call expression to a specified filter Lambda.

Example1

filter run "myFilter";

This will run the "myFilter" FilterLambda, in the current project, on the current table view. The backup table view will not be altered.

Notes and Hints

Any names will be NOT treated as table row field references.

Example2

filter run stockWizard.filterMe(cursor); 

This will call the stockWizard.filterMe FilterLambda, passing the current table view as an argument.

Notes and Hints

Any names will NOT be treated as table row field references.

Filter Command: set

The set command performs a update on the current table cursor.
Syntax: set fieldName=expression

set Mandatory keyword
fieldName Name of the field, in each row of the current view, which is to be set with a new value.
= Optional assignment symbol
expression The new value which is to be set into each row of the current view.

Example1

filter set Score 1; 
filter set Score = 1; 

This will set the Score field to 1, in all rows in the current table view. The current table view will be replaced with the new backup view. The backup table view will be permanently altered.

Notes and Hints

Any names will be treated as table row field references.

Filter Command: setnr

The setnr command performs a update on the current table cursor without reseting the current view.
Syntax: setnr fieldName=expression

setnr Mandatory keyword
fieldName Name of the field, in each row of the current view, which is to be set with a new value.
= Optional assignment symbol
expression The new value which is to be set into each row of the current view.

Example1

filter setnr Score 1; 
filter setnr Score = 1; 

This will set the Score field to 1, in all rows in the current table view. The current table view will not be reset. The backup table view will be permanently altered.

Notes and Hints

Any names will be treated as table row field references.

Filter Command: slice

The slice command performs an ascending sort on the current table cursor, followed by a tile operation on the current table cursor.
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

filter slice Sales * Price 42 of 100;

This will retain all rows from the current table view which are in the 42 percentile of (Sales * Price). Any rows, where Sales or Price are #void, will be eliminated from the current table view. The backup table view will not be altered.

Notes and Hints

Any names will be treated as table row field references.

Filter Command: sort

The sort command performs a sort on the current table cursor.
Syntax: sort [backup] [direction] sortexpression

sort Mandatory keyword
backup Optional keyword to specify that the backup view of the table is to be sorted as well as the current view.
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

filter sort down Name;

This will sort all rows in the current table view in descending order by Name. Any rows, where Name is #void, will be eliminated from the current table view. The backup table view will not be altered.

Notes and Hints

Any names will be treated as table row field references.

Filter Command: top

The top command performs a sort on the current table cursor, followed by a deletion operation on the current table cursor.
Syntax: top sortexpression cutoff

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

Example1

filter top Salary 10%;

This will delete all rows from the current table view which are not in the top 10% of all Salaries. Any rows, where Salary is #void, will be eliminated from the current table view. The backup table view will not be altered.

Notes and Hints

Any names will be treated as table row field references.

 

for

The for statement repeats a set of javaScript 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 javaScript 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.
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 javaScript 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.

function

A javaScript 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 }
Syntax: 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 javaScript 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

javaScript 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 ()
Syntax: name (arg ...)
Syntax: Lambda.child ()
Syntax: Lambda.friend ( arg ...)
Syntax: class.method ()
Syntax: 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... }
Syntax: if (test) { trueClause... } else { elseClause... }
Syntax: 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. javaScript performs type checking and type conversions, therefore if the operands are not Boolean, the operands are converted to Boolean.
Syntax: (obj1 && obj2 )
Syntax: (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 javaScript 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 javaScript 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

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 javaScript 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' )
		
					Syntax: new ('String' , value)
		
					Syntax: new ('Symbol' , value)
		
					Syntax: new  ('Vector' , vecSubType,  size)
		
					Syntax: new  ('Vector',  vecSubType,  size,  value)
		
					Syntax: new  ('Structure',  key,  value)
		
					Syntax: new  ('Structure',  key,  value ... . cdr )
		
					Syntax: new  ('Dictionary',  key,  value)
		
					Syntax: new  ('Directory',  key,  value)
		
					Syntax: 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

javaScript 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 javaScript 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 javaScript 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 
		
					Syntax: pvar varName = init
		
					Syntax: pvar type varName 
		
					Syntax: 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 javaScript 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 javaScript 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 javaScript 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
Syntax: reg varName=init|
Syntax: reg type varName
Syntax: 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!

score

The score statement performs a set of scoring operations on the dataMineLib.currentTable cursor. The score statement must be followed by a single command. The score statement supports commands for averaging and totalling rows from the current view index. The score statement does not alter the current table view. The backup table index is not altered by the score statement.
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, cursor, contains the dataMineLib cursor which is to be filtered.

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

(lambda (cursor)
(begin ?score statement block?)
)

Note3: The score statement always automatically converts any name symbol into a row field reference.

Score Command: average

The average command averages a numeric expression over each row in the current table cursor.
Syntax: average expression

average Mandatory keyword
expression Numeric expression.

Example1

score average Sales;

This will return the average of Sales for the current table. Any rows, where Sales are #void, will be treated a zero values in the average. The current table view will not be altered. The backup table view will not be altered.

Notes and Hints

Any names will be treated as table row field references.

Score Command: averageForAll

The averageForAll command averages a numeric expression over ALL rows in the current table cursor.
Syntax: averageForAll expression

averageForAll Mandatory keyword
expression Numeric expression.

Example1

score averageForAll Sales;

This will return the average of Sales for the backup table. Any rows, where Sales are #void, will be treated a zero values in the average. The current table view will not be altered. The backup table view will not be altered.

Notes and Hints

Any names will be treated as table row field references.

Score Command: total

The total command totals a numeric expression over each row in the current table cursor.

Syntax: total expression

total Mandatory keyword
expression Numeric expression.

Example1

score total Sales;

This will return the total of Sales for the current table. Any rows, where Sales are #void, will be treated a zero values in the total. The current table view will not be altered. The backup table view will not be altered.

Notes and Hints

Any names will be treated as table row field references.

Score Command: totalForAll

The totalForAll command totals a numeric expression over ALL rows in the current table cursor.
Syntax: totalForAll expression

totalForAll Mandatory keyword
expression Numeric expression.

Example1

score totalForAll Sales;

This will return the total of Sales for the backup table. Any rows, where Sales are #void, will be treated a zero values in the total. The current table view will not be altered. The backup table view will not be altered.

Notes and Hints

Any names will be treated as table row field references.

Statement Blocks

An arbitrary number of javaScript 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 javaScript 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);} 

var

The var statement declares a temporary variable inside a javaScript 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 javaScript 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
Syntax: var varName=init|
Syntax: var type varName
Syntax: 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 javaScript 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 javaScript 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 javaScript 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  

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