# 2.6. Object system¶

This chapter describes the object system.

## 2.6.1. Values¶

A value is a unit of data, such as a number, a function or a container of values. For example, each line of this example produces a value.

```'Foo'
42
{(:Num) Num * 2 }
```

Value has a variable mapping, and optionally intrinsic properties.

Intrinsic properties of a value are any data contained in the value not via the variable mapping. The examples are the identity of a value, a character sequence of a string value, and bytes of a number value. Intrinsic properties cannot be accessed directly from Kink programs, but can be used by the runtime, functions implemented in the platform language (typically Java), and so on. Due to existence of intrinsic properties, values which have the same variable mapping may perform differently.

## 2.6.2. Variables¶

A value has a variable mapping, which is a finite partial mapping from strings to values.

A variable is a pair of a value and a string. If a variable V is a pair (O, S) where O is a value and S is a string, O is said to be the owner of the variable V, and S is said to be the symbol of the variable V.

For simplicity, a variable V whose symbol is S can be referred as “variable S,” when it is clear which value is the owner.

When a symbol S is defined in the domain of the variable mapping of a value O, O is said to have a variable (O, S), and the variable is said to be nonempty.

When a symbol S is mapped to a value T by the variable mapping of a value O, T is said to be the target of the variable (O, S).

From definitions above, a variable mapping can also be represented as a set of pairs of symbols and targets. For example, {(s1, t1), (s2, t2), ... (sn, tn)}, where a string si is mapped to a value ti by the variable mapping.

## 2.6.3. Assignment¶

A value Tn can be assigned to a variable (O, S). Such action is called assignment.

Let O have a variable mapping Mo. After assignment, O gets to have a new variable mapping Mn, which can be different from Mo.

It must be distinguished whether S is defined in the domain of Mo.

When S is defined in the domain of Mo

Let S be mapped to a value To by Mo, and Mo be a mapping {(S, To), (s1, t1), (s2, t2), ... (sn, tn)}.

In this case, Mn is the mapping {(S, Tn), (s1, t1), (s2, t2), ... (sn, tn)}.

When S is not defined in the domain of Mo

Let Mo be a mapping {(s1, t1), (s2, t2), ... (sn, tn)}.

In this case, Mn is the mapping {(S, Tn), (s1, t1), (s2, t2), ... (sn, tn)}.

Example

The program below assigns numbers to variables of a value `Point`, and gets the targets from them.

```# (1)
:Point <- new_val

# (2)
Point:X <- 10
Point:Y <- 20

stdout.print_line(
[Point:X.nonempty? Point:Y.nonempty? Point:Z.nonempty?].repr
) # => [true true false]
stdout.print_line(
[Point.X Point.Y].repr
) # => [10 20]

# (3)
Point:Y <- 200
Point:Z <- 300

stdout.print_line(
[Point:X.nonempty? Point:Y.nonempty? Point:Z.nonempty?].repr
) # => [true true true]
stdout.print_line(
[Point.X Point.Y Point.Z].repr
) # => [10 200 300]
```

On (1), a value is created by `new_val` function, and it is assigned to the local variable `Point`. The value already has several variables such as `repr` and `var_syms`.

On (2), the number 10 is assigned to the variable `X`, and 20 to `Y`. The variable mapping here is:

Symbol Target
X 10
Y 20
... ...

On (3), the number 200 is assigned to the existing variable `Y`, and 300 to the new variable `Z`. The variable mapping here is:

Symbol Target
X 10
Y 200
Z 300
... ...

## 2.6.4. Variable references¶

A variable reference, or a varref is a value which represents a variable. Operations such as assignment or existence checking are done through variable references.

Variable references can be typically created by local reference expressions (`local_ref`) or attributional reference expressions (`attr_ref`). For example, this expression creates a reference of a variable `Data`, whose owner is `Owner`.

```Owner:Data
```

This expression creates a reference of a variable `fun`, whose owner is `Owner`.

```Owner:fun
```