[Oberon] open array usage

Christian Demmer chris at gcjd.de-web.ws
Sat Jul 10 18:46:47 MEST 2010


spir wrote:
>Sorry for coming back to the topic, but I still cannot figure out how open arrays are supposed to be used in Oberon, without any form of literal notation.
>
>PROCEDURE Sum(reals:ARRAY OF REAL) : REAL ;
>PROCEDURE Max(reals:ARRAY OF REAL) : REAL ;
>How can one pass [1,2,3] or [a,b,c] to one of those procedures?

VAR
  in : ARRAY 3 OF REAL;
  s  : REAL;
BEGIN
  in[0] := 1; in[1] := 2; in[2] := 3;
  s := Sum(in);
  
But probably that is not what you really want. I have the impression you
are trying to emulate the variable number of arguments to a function
feature. That won't work in Oberon.

>
>TYPE STRING = POINTER TO ARRAY OF CHAR ;
>PROCEDURE concat(ARRAY OF STRING) : STRING ;
>PROCEDURE write(ARRAY OF STRING) ;
>
>How can one concat or write ["Hello, ", name, ", how do you do?"]?

I think you can't. Constants are mostly compile time features (strings
beeing somewhat special) in Oberon compilers. You cannot get a pointer
to a constant.

>Is there an answer?
>If not, how to achieve that, or anyhow work around the issue?

Hmm. I am not sure what the issue is. Probably you can describe what you
are trying to do on the problem level. Then it would be easier to
suggest an Oberon style solution. 

>Side-question: how to define an Oberon equivalent to Pascal's write?

You don't. You are still trying to have variable / untyped argument
lists in Oberon. :-)

Out.String("Value :") Out.Real(v, 10); Out.Ln;

is probably one Oberon way.

Greetings, Christian


More information about the Oberon mailing list