[Oberon] Oberon-2 type bound procedure scope

Joerg joerg.straube at iaeth.ch
Thu Dec 7 02:49:00 CET 2023


Ciao Stefano

In your description you used „procedure scope“ and „outer scope“ implying somehow that there are two scopes. But in fact there are three scopes involved:
- the outer (global) scope
- the Tree scope
- the procedure scope

The receiver part has in fact two tasks
a) selecting the Tree scope to tell the compiler to add „AddNode“ to Tree.
If the procedure was not type-bound, „AddNode“ would be added to the global scope.
b) opening the procedure scope, tree gets the first formal parameter. In the procedure you have access all local variables, all parameters, all data of the tree scope and all global variables.

As you find it weird, which syntax for type-bound procedures would you have preferred?

Saluti
Jörg

> Am 07.12.2023 um 05:44 schrieb Diego Sardina <dsar at eml.cc>:
> 
> On Wed, Dec 6, 2023, at 23:54, Stefano Ferrari wrote:
>> 
>> Consider a type bound procedure declaration
>> 
>> PROCEDURE (tree: Tree) AddNode(node: Node);
>> 
>> Where does the procedure scope start?
>> Identifier ‘tree’ (receiver) belongs to the procedure scope, identifier ‘AddSymbol’ belongs to outer scope and then identifier ‘node’ belongs to procedure scope again
>> 
>> Weird, isn’t it?
>> 
> 
> Ciao Stefano :-)
> 
> I don't generally see a big problem with that syntax, except maybe in an extreme single-pass compiler where the scope is built at the symbol level. Even in that case once you see the first "(" you know that it's a type bound procedure and you expect a parameter that will be part of the scope of the following procedure declaration.
> 
> Why do you consider it so weird?
> 
> --
> Diego Sardina
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon


More information about the Oberon mailing list