definitions.txt 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. Definitions
  2. ===========
  3. A Nim program specifies a computation that acts on a memory consisting of
  4. components called `locations`:idx:. A variable is basically a name for a
  5. location. Each variable and location is of a certain `type`:idx:. The
  6. variable's type is called `static type`:idx:, the location's type is called
  7. `dynamic type`:idx:. If the static type is not the same as the dynamic type,
  8. it is a super-type or subtype of the dynamic type.
  9. An `identifier`:idx: is a symbol declared as a name for a variable, type,
  10. procedure, etc. The region of the program over which a declaration applies is
  11. called the `scope`:idx: of the declaration. Scopes can be nested. The meaning
  12. of an identifier is determined by the smallest enclosing scope in which the
  13. identifier is declared unless overloading resolution rules suggest otherwise.
  14. An expression specifies a computation that produces a value or location.
  15. Expressions that produce locations are called `l-values`:idx:. An l-value
  16. can denote either a location or the value the location contains, depending on
  17. the context. Expressions whose values can be determined statically are called
  18. `constant expressions`:idx:; they are never l-values.
  19. A `static error`:idx: is an error that the implementation detects before
  20. program execution. Unless explicitly classified, an error is a static error.
  21. A `checked runtime error`:idx: is an error that the implementation detects
  22. and reports at runtime. The method for reporting such errors is via *raising
  23. exceptions* or *dying with a fatal error*. However, the implementation
  24. provides a means to disable these runtime checks. See the section pragmas_
  25. for details.
  26. Whether a checked runtime error results in an exception or in a fatal error at
  27. runtime is implementation specific. Thus the following program is always
  28. invalid:
  29. .. code-block:: nim
  30. var a: array[0..1, char]
  31. let i = 5
  32. try:
  33. a[i] = 'N'
  34. except IndexError:
  35. echo "invalid index"
  36. An `unchecked runtime error`:idx: is an error that is not guaranteed to be
  37. detected, and can cause the subsequent behavior of the computation to
  38. be arbitrary. Unchecked runtime errors cannot occur if only `safe`:idx:
  39. language features are used.