Variables are usually sequences of letters, underscores and digits but may not start with a digit. This will be familiar to all programmers. Furthermore, a couple of dozen name are set aside for special roles; these are usually referred to as the reserved words.
Variables may also be sequences of sign characters such as $, %, ^, & and so on. This aspect of the language may be developed further in the future. However, it is recommended you do not make use of this fact until further notice.
In MillScript, in complete contrast to C, C++, or Java a variable name has one and only one meaning i.e. there is only one name space. This has some very definite practical implications. When you see an expression such as
foo( bar.gort() + 1 )
you should 'see' four variables foo, bar,
gort, and +! Yes, + is an
ordinary variable. Its role as an infix operator is a property of
MillScript's grammar - a fine distinction, maybe.
Variables are always assigned to when they are first introduced
using the var syntax. e.g.
var x = 99;
It is not possible to have an unassigned variable in MillScript because it is mandatory to assign its initial value.
By default, variables are untyped and assignable. It is perfectly normal for a variable to have a boolean value one moment and a string value the next. In future versions of MillScript it will be possible to restrict variables to a given type and to prevent assignments (after the first).
Assignments are written using the := operator. [This is
deliberately different from the = used in the
var syntax, incidentally, for reasons of future
extensibility.] Putting this together, the following program
fragment is perfectly ok :-
var x = 0;
x := "foo";
Assignments never return any results. As a consequence, in simple assignments, the right hand side is constrained to return a single value. A run-time error is reported if this is not adhered to.
x := "this is ok"; # yes it is.
x := 'whoops!'; # because 'whoops!' returns seven characters