Values, Spaces, and Places

The result of an expression in Vine has one of three forms: a value, a space, or a place.

We’ll use the following code example to explore these concepts further.

let x = 1 + 2;
x + 1;
x = 5;
x *= 2;

On line 1, the expression 1 + 2 results in the value 3. The variable x is then declared with an initial value of 3.

On line 2, the expression x results in its value 3, so the expression x + 1 results in the value 4. This expression is unused so its result is simply discarded.

On line 3, we have an assignment statement. This expects a space on the left-hand side, and a value on the right-hand side, and will put the value into the space. In this particular case, the expression x on the left-hand side results in a space – whatever value is put into this space will become the new value of x. Then, the assignment operator puts the value 5 into the space. The value of x is now 5.

On line 4, the *= operator expects a place on the left-hand side, and a value on the right-hand side. Thus, x results in its place, which is the combination of the value 5 and a space to put a new value for x. The *= operator uses the value to calculate 5 * 2, and puts the value 10 into x’s space. Thus, the value of x is now 10.

Expression Resolution

Expression Positions

Every expression is located in either a value position, a space position, or a place position. The form of the expression’s position determines the form of the result of the expression.

We saw above that the expression x could result in a value, a space, or a place; this is determined by the form of its position.

Expression Forms

Independent of its position, every expression has a form – it is either a value expression, a space expression, or a place expression. For example, variable expressions, like x, are place expressions.

The form of an expression determines the form of what the expression evaluates to. If this form does not match the form of the expression’s position, it is coerced to become the result.

Coercion

There are three rules for coercion:

These rules result in the behavior described in the first section.