mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 01:44:37 +00:00
50 lines
2.1 KiB
Plaintext
50 lines
2.1 KiB
Plaintext
|
|
Definitions
|
|
===========
|
|
|
|
A Nim program specifies a computation that acts on a memory consisting of
|
|
components called `locations`:idx:. A variable is basically a name for a
|
|
location. Each variable and location is of a certain `type`:idx:. The
|
|
variable's type is called `static type`:idx:, the location's type is called
|
|
`dynamic type`:idx:. If the static type is not the same as the dynamic type,
|
|
it is a super-type or subtype of the dynamic type.
|
|
|
|
An `identifier`:idx: is a symbol declared as a name for a variable, type,
|
|
procedure, etc. The region of the program over which a declaration applies is
|
|
called the `scope`:idx: of the declaration. Scopes can be nested. The meaning
|
|
of an identifier is determined by the smallest enclosing scope in which the
|
|
identifier is declared unless overloading resolution rules suggest otherwise.
|
|
|
|
An expression specifies a computation that produces a value or location.
|
|
Expressions that produce locations are called `l-values`:idx:. An l-value
|
|
can denote either a location or the value the location contains, depending on
|
|
the context. Expressions whose values can be determined statically are called
|
|
`constant expressions`:idx:; they are never l-values.
|
|
|
|
A `static error`:idx: is an error that the implementation detects before
|
|
program execution. Unless explicitly classified, an error is a static error.
|
|
|
|
A `checked runtime error`:idx: is an error that the implementation detects
|
|
and reports at runtime. The method for reporting such errors is via *raising
|
|
exceptions* or *dying with a fatal error*. However, the implementation
|
|
provides a means to disable these runtime checks. See the section pragmas_
|
|
for details.
|
|
|
|
Whether a checked runtime error results in an exception or in a fatal error at
|
|
runtime is implementation specific. Thus the following program is always
|
|
invalid:
|
|
|
|
.. code-block:: nim
|
|
var a: array[0..1, char]
|
|
let i = 5
|
|
try:
|
|
a[i] = 'N'
|
|
except IndexError:
|
|
echo "invalid index"
|
|
|
|
An `unchecked runtime error`:idx: is an error that is not guaranteed to be
|
|
detected, and can cause the subsequent behavior of the computation to
|
|
be arbitrary. Unchecked runtime errors cannot occur if only `safe`:idx:
|
|
language features are used.
|
|
|