Dynamic local array implementation
On Sun Oct 15 17:49:13 CEST 2017 Diego Sardina wrote:
Note that this can cause aliasing problems, expecially in multithreading programs. One has to copy the content of the structure parameter in a local variable to make sure that it remains constant (and consistent) during the whole processing.
Yes, a "mutable copy" of a value parameter.
This is also where an OUT parameter would be very useful.
Of course, one could always do that. But then one would have *three* types of procedure parameters in the language. Over the years, various other languages have experimented with that possibility. For example, we had a fairly elaborate (and in fact quite similar) debate on that topic in the Swift programming language as well - originally, Swift also had *three* types of parameters: value, “var" and “inout”. (value was clear, but both “var” and “inout" gave a mutable local copy of a value, but parameters marked inout are automatically written back). In the end, a decision was made to eliminate “var” and keep “inout” in the language. I presume Swift “inout” it is close to what you mean by OUT. -AP
On Sun, Oct 15, 2017, at 06:19 PM, Andreas Pirklbauer wrote:
I presume Swift “inout” it is close to what you mean by OUT.
Uhm... I don't know Swift, but I see inout more like a by value-result strategy while an out parameter is a by result strategy. There is also a nice exercise in Wirth's compiler book (page 81) that asks to replace the VAR parameter concept by the notion of an OUT parameter. It says that it's the inverse of the value parameter. However, taking the current semantic of Oberon-07 (all structured parameters are by reference) we can simulate these strategy modes in this way: TYPE Person = RECORD ... END; (* By value *) PROCEDURE Foo (p: Person); VAR p1: Person; BEGIN p1 := p; (* working on p1 ... *) END Foo; (* By value-result *) PROCEDURE Foo (VAR p: Person); VAR p1: Person; BEGIN p1 := p; (* working on p1 ... *) p := p1 END Foo; (* By result *) PROCEDURE Foo (VAR p: Person); VAR p1: Person; BEGIN (* working on p1 ... *) p := p1 END Foo; By result is what I meant with an OUT parameter. -- Diego Sardina
participants (2)
-
Andreas Pirklbauer -
Diego Sardina