Extending | Variables | Types | Units | Literals | Lists | Aspects |
Ocean, as any (computer) language, is based on certain concepts. To ease the understanding of Ocean most important concepts are summarized here. Note that this text assumes that the reader knows a few 3rd generation languages.
Most languages only execute their code when 'running' the program. Some have some kind of 'compile time execution' in the form of a preprocessor, templates or such like. Ocean allows parts of a program to be executed 'compile time', making seamless language extension possible: for example precompiled regular-expressions, automatic list building and more.
Running programs use storage for the program (compiled or interpreted) and for intermediate results. All these things (which consume storage or have a memory address) are called 'variables' in Ocean. Not all 'variables' can be changed, not all variables can created whenever or whereever, still, if it is 'real' (has a memory address) it is a 'variable'.
Where variables are pieces of memory, types indicate the meaning of those pieces. A certain bit pattern can be a float, and integer, or an instruction (or all of them), so the type of the variable tells Ocean what the allowed operations are.
Types are abstract! Ocean will keep track of the type during compilation, but no type info will be stored in the executable. If this is a problem, please read the Object-Oriented part of how to circumvent this.
Do not use a type for 'meter' and another for 'second', use units instead.
There is no generic 'value of this variable is the memory address of other variable'. There are several pointer derivatives, see structures and arrays and objects.
All types except for classes are content equivalent, that is, if number, order, type, and subranges of the components are identical, then variables of compounds are considered to be of identical type.
Classes are name equivalent: only variables declared with the same class nameare considered to be of identical type.
Each variable can have a unit. Units are a kind of 'subtype': you can only mix units in certain ways: you can for example multiply two different units, but you cannot add them. Note that the destination variable must have the correct unit too. Units can be 'elementary' or 'derived'. Variables with derived units are converted/stored in the elementary form (caveat emptor), but are 'printed' (thus converted back) in their derived form.
Literals are not types. Literals (numeric or text) denote an abstract value, but without any internal representation. The 'compile time code' is responsible for translating literals into a binary representation. As literals have no type, it is either derived from context, or by explicit 'casting'. A literal can have a unit, which must then match the variable! Note that you cannot 'cast' a variable: it already has a type.
A word about precision: the Ocean rule is that integer and real literals consisting of an integer with an exponent have infinite precision. Reals with a decimal point have a precision depending on the amounts of digits, ignoring leading zeros but counting trailing zeros.
...
Reflection, the ability to discover facts about Types, Variable and such, can make a huge difference between odd errors and a correct working program.