Other Operators

Other Operators

Operator Description
Define x:=y 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:
Procedure {x,y,...} 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 created as a side effect of the expressions x, y, or z.
Parentheses (x,y,...) DScript treats a set of expressions inside parentheses just as it does expressions inside braces, except 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:
Do Primitive @x It is possible to replace primitives inside DScript simply by creating a node with the same name. You can ensure the primitive version of a function is called by placing an ampersand in front of the primitive name. For example:
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 prompts the user for information. Age:=asknumber("How old are you?") If Age has already been evaluated, then the expression ?Age returns the user's previous answer. If Age has not been evaluated yet, ?Age returns 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 causes its definition to be activated and the user is prompted for a response. The Value Of operator simply prevents the node's definition from being activated.
typeof typeof x 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.
void void x 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 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 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.