|
  
Nodes
When you write an application using DScript, you are building
a collection of nodes. The tree editor helps you create, change,
and delete nodes. It also displays the nodes in a way that shows
you how they are dependent upon one another. This style of
presentation helps you manage the collection of nodes more
easily.
A node contains several properties including:
o Definition
o Form
o Comment
o Node display format
o Value display format
o Calculated value
o Runtime attributes
Many of these properties are cosmetic. That is, they simply
affect how the node appears in your tree. The definition,
however, determines what the node does. For this reason, the
definition is the most important part.
You create a node by entering its definition in the tree
editor's Formula Window. Since default values are used for all
other properties of the node, the definition is the only part you
need to define.
Nodes are created by entering a definition with the format
Name( arguments ) := statement
Name is the name of the node, (arguments) is an
optional list of input arguments, and statement is a
formula, statement, or statement block that defines the node's
function.
Note that you use the Define
operator (:=) to create a definition rather than use the Assign operator (=). Assign is used to store a value in
an existing variable. Define
creates a new node definition, but does not execute it or assign
a value to it.
If you enter a definition without input arguments, you get a Constant:
Profit:=Sales-Costs
If you include arguments, you get a Function:
Pythag(x,y):=sqrt(x*x+y*y)
The right-hand side in both of these examples includes only a
single statement. These types of definitions are called simple.
If the right-hand side includes a statement block, the definition
is called compound. A statement block is simply a
list of statements enclosed in braces { }. The following is
an example of a compound constant.
Profit:={
var sales=100;
var costs=60;
sales-costs;
}
Similarly, the following is a compound function:
Pythag(x,y):={
var x2=x*x;
var y2=y*y;
sqrt(x2+y2);
}
When DScript executes a statement block, it simply executes
each statement in the order they are listed and returns the value
of the last statement.
Other definitions can call constants simply by using their
names as in the following example:
ROE:=Profit/Equity
You call functions by using their names followed by a list of
argument values. For example,
Magnitude:=Pythag(3,4)
Note that when you call Profit you do not place a pair
of parentheses after the node name. That is, use Profit instead of Profit(). Most other programming
languages require you to use parentheses every time you call a
subroutine. With DScript, you don't need to do this so long as
the node you are calling is defined as a constant.
You will learn later that constants are a very powerful yet
unique programming concept. Constants, as supported by DScript,
are unlike anything found in traditional languages.
|