Oberon Community Platform

Edit Page
Printable View


What are CONST parameters? What are they good for?

CONST parameters are treated like variable (VAR) parameters except that you are not allowed to change their actual values. Arguments are therefore passed by reference and there is no need to copy them on the stack. This is primarily useful to pass arrays of arbitrary length, but especially arrays of characters. CONST allows the caller to pass arrays more efficiently (in time and space) and guarantees at the same time, that the array won't be modified by the callee.

Consider the following example where copying the string does not make much sense but was actually necessary before we introduced CONST parameters.

BEGIN len = 0; WHILE string[len] # 0X DO INC (len) END; RETURN len;
END Length;

As the interface of the procedure Length guarantees that arguments won't be modified although they are passed by reference, it is now even possible to pass string literals:

ASSERT (Length ("Hello") = 5);

What are module contexts? How are they used?

Module contexts are single-level namespaces that allow modules with the same name to co-exist at the same time. They were introduced to clearly separate modules belonging to Oberon and A2 (previously Aos). Therefore there are currently two contexts defined: A2 and Oberon, whereas A2 is the default one.

Modules intended to be run within the Oberon system have to belong to the Oberon context. This is specified by code as in this sample module:

MODULE Test IN Oberon;
END Test.

If the context of an imported module is not explicitly specified as for Streams, it defaults to the context of the module, which is Oberon in this example.

Following the naming conventions established since revision 1319 for all Oberon modules, the filename of this example should be prefixed by Oberon and reads therefore Oberon.Test.Mod.

Compilation of MODULE <ModuleName> IN <ContextName>; ... produces an object file named <ContextName>.<ModuleName>.<Extension>. Typical extensions are "Obx" in Native A2, "Obj" in UnixAos and "Obw" in WinAos. In the preceding example in A2, the object file name is "Oberon.Test.Obx".

The original pdf document has more information.

Copyright © 2007 ETH Zürich
Page last modified on September 19, 2013, at 03:51 PM