Simple Expressions

Parentheses: "(" and ")"

Any expression can be enclosed in a pair of matching parentheses, typically in order to override operator precedence. e.g.

2 * ( 3 + 4 );
        

Sadly, the parenthesis is an exception to the principle that each syntactic element has one and only one job - because it is, of course, also used for function application. e.g. f(x). This has become such established practice, there's nothing to be done about it.

Arithmetic Operators

MillScript has a small complement of arithmetic operators which will be extended on demand. e.g.

2 + 3 * 4 - 7;
        

Note that + does not work on strings - that is an evident design error in both Java and JavaScript. Use the polymorphic append operator, ++, instead.

Relational Operators

MillScript has the usual complement of relational operators, namely <, <=, =, ==, /=, /==, >= and >. As is usual, the comparison operators only work on numbers but equality can be used on any data type. Note that the "/" character is used to negate the sense of an equality operator.

The difference between the identity operator == and the equality operator = needs to be spelled out. Two values are identical if they are pointers to the address - n.b. all MillScript values are actually pointers. They are equal if they are of the same type, size and have equal components. Obviously enough, == is both less expensive and less useful than =.

Take special care with = because, unlike Java, MillScript uses the equals sign to mean "Object.equals". If you want assignment you must use the assignment operator :=. However, MillScript follows the more obvious Algol approach, popularized by Pascal, in using the equals sign to mean (gasp!) equals.

A remark for the future: the parent language Spice allows you to write "chains" of comparisons such as 0 <= x < 100 and this elegant feature will be included in a future version of MillScript.

Short-Circuit Absent-Based Operators

Although MillScript conditionals require booleans, it is often the case that one wants to used absent-based or nullean logic. The special operators && and || are used for this.

The easiest way to understand these operators is to expand them into explicit if-expressions. However, these expansions aren't quite right since they suggest double evaluation for the first argument. Naturally enough, the operators only evaluate their arguments once.

x && y      if x /== absent then y else absent endif
x || y      if x == absent then y else x endif