Vanguard Software
Forecasting & Planning Solutions
Home Products Solutions Services Customers Partners Company
 
Applying science to business management

contents.gifindex.gifprev1.gifnext1.gif

Other Operators

Define x:=y

The Define operator is used to create node definitions. Normally, you create node definitions at design-time by entering definitions in the formula window. However, you can also create additional definitions at runtime by executing statements with the Define operator.

The operand x is a node name with an optional set of input arguments. The operand y is the node definition. For example,

Pi:=3.14

f(x):=(1+2x)*x

sum(list):={
var total=0;
for(var n=0; list[n]!=null; n++)
  total+=list[n];
return total;
}

Procedure {x,y,...}

You can define a set of expressions to be evaluated by enclosing them in braces. Braces also create a new block scope that prevents variables declared inside the braces from interfering with variables in other functions. DScript evaluates the expression {x,y,z} as follows. First, DScript creates a new block scope. Next, it evaluates the expressions x, y, and z in that order. Finally, DScript deletes any variables or new nodes that were created as a side effect of the expressions x, y, or z.

Parentheses (x,y,...)

DScript treats a set of expressions inside parentheses just like it does expressions inside braces, except that no new block scope is created and new variables created inside the parentheses persist.

Function Call x()

After assigning a function pointer to a variable, you can explicitly call the function by placing a pair of parentheses after the variable name. For example,

var f=MyFunction; // pointer to MyFunction(x)
f(2)  // same as MyFunction(2)

Do Primitive @x

It is possible to replace primitives inside DScript simply by creating a node with the same name. You can ensure that the primitive version of a function is called by placing an ampersand in front of the primitive name. For example,

var a;
a=sqrt(16); //
a = 4 (square root of 16)
sqrt(x):=x/2; // replace sqrt
a=sqrt(16); // a = 8 (call new sqrt)
a=@sqrt(16); // a = 4 (call primitive sqrt)

Value Of ?x

Nodes have both a definition and a calculated value. The Value Of operator returns a node's value without executing its definition. For example, the following node will prompt the user for information.

Age:=asknumber("How old are you?")

If Age has already been evaluated, then the expression ?Age will return the user's previous answer. If Age has not been evaluated yet, ?Age will return null. Contrast this to the expression Age without the question mark. In this case, if Age has already been evaluated, the user's previous response is returned (just like with ?Age). However, if Age has not been evaluated yet, referring to its name will cause its definition to be activated and the user will be prompted for a response. The Value Of operator simply prevents the node's definition from being activated.

typeof typeof x

The typeof operator is used to determine the type of data contained in x. Typeof returns a text string with the value "number", "string", "boolean", "object", etc. as is indicated in the table below. Note that lists are classified as "object" by typeof.

Returns Data Type

undefined null

boolean Logical value true or false

number Any real or complex number

string Text string

object List or object

function Function pointer

You may want to consider using the primitive dtype instead of typeof.

void void x

The void operator evaluates the expression x and then discards its value. There is little practical application of this operator in DScript. It is supported largely to maintain compatibility with JavaScript.

Conditional x?y:z

The Conditional operator performs a simple if/then/else construct. First, the expression x is evaluated. If it is true, then y is evaluated; otherwise, z is evaluated. The value of y or z (whichever was evaluated) is returned.

Accumulate x->y

The Accumulate operator is used to build decision trees. Accumulate performs the following steps:

1) Evaluate x and add its value to the global accumulator.

2) Evaluate y.

3) Subtract the value of x from the global accumulator.

4) Return the value of y.

If no expression is supplied for y, then Accumulate returns the value of the global accumulator.

  Demand Planning  |  Financial Forecasting
Forecasting Software  |  Strategic Planning Software  |  Decision Tree Software
Decision Support Software  |  Expert System Software  |  Online Surveys

Contact Us  |  Terms of Use  |  Privacy Policy  |  Site Map
Vanguard Software
© 2011 Vanguard Software Corporation
Print this page   Email this page to a friend