//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2010, 2026 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available
// under the terms of the MIT License which is available at
// https://opensource.org/licenses/MIT
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////

include::../_part_attributes.asciidoc[]

:leveloffset: -2

[[lang-tut-values-chapter-types-values-exprs]]
== Types, values, and expressions

This lesson explains the difference between types, values, and expressions.
These concepts have already been used in previous lessons, but this lesson names them explicitly, and also explains the relations between them.
Furthermore, this lesson serves as an introduction for the coming lessons, which rely heavily on these concepts.
Consider the following declarations of <<lang-tut-data-chapter-discrete-variables,discrete variables>>:

[source, cif]
----
disc int x = 1;
disc int y = 2 * x;
----

indexterm:[type]
indexterm:[value]
The first declaration declares a discrete variable named `x`, and the second declaration declares a discrete variable named `y`.
Both variables have an `int` _data type_.
A data type is usually just called a _type_, if there is no confusion with other kinds of types.
The type of a variable indicates the potential or allowed values of the variable.
Variable `x` is initialized to _value_ `1`.
Variable `y` is initialized to twice the value of `x`, meaning it is initialized to value `2`.

indexterm:[expression]
indexterm:[expression,computation]
indexterm:[expression,evaluation]
Both `1` and `+2 * x+` are _expressions_.
Expressions are combinations of among others literal values (e.g. `1`), variables (e.g. `x`), and operations (e.g. `+*+`) on them.
Expressions can be _computed_, resulting in a value.
This is called _evaluation_ of the expression.

Expression `+2 * x+` can be evaluated.
Evaluating the expression results in value `2` if the value of `x` is `1`, and in value `4` if the value of `x` is `2`.
Expressions can thus be evaluated to different values, depending on the values of the variables that occur in them.

indexterm:[literal]
indexterm:[expression,literal]
indexterm:[literal,expression]
indexterm:[value,literal]
indexterm:[literal,value]
indexterm:[expression,constant]
indexterm:[constant,expression]
indexterm:[value,constant]
indexterm:[constant,value]

[[lang-tut-values-types-values-exprs-literal]]
Expression `1` consists of only a single value, called a _literal_ value expression.
Evaluation always results in that single value.
Expression `1 + 3` evaluates to value `4`.
Even though it does not consist of only just a literal, the value is the same for each evaluation.
The expression represents a _constant_ value.
