[Oberon] open array usage
Bob Walkden
bob at web-options.com
Sat Jul 10 18:25:48 MEST 2010
You have to declare a variable whose type is an array, and populate the elements individually. This is for Blackbox:
TYPE
Denis = ARRAY 3 OF REAL;
VAR
d: Denis;
PROCEDURE Sum(reals:ARRAY OF REAL) : REAL ;
VAR i : INTEGER;
x: REAL;
BEGIN
x := 0.0;
FOR i := 0 TO LEN( reals )-1 DO
x := x + reals[i];
END;
RETURN x;
END Sum;
PROCEDURE T2*;
BEGIN
d[0] := 1.1;
d[1] := 2.2;
d[2] := 4.4;
Out.Real( Sum( d ),7 );
END T2;
Pascal's WRITE is a method of writing text to the screen. Oberon has a more interesting and general solution, but you can use procedures in the Out module to write text to the log.
Bob
> -----Original Message-----
> From: oberon-bounces at lists.inf.ethz.ch [mailto:oberon-
> bounces at lists.inf.ethz.ch] On Behalf Of spir
> Sent: 10 July 2010 16:40
> To: Oberon
> Subject: [Oberon] open array usage
>
> Hello,
>
>
> 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?
>
> 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?"]?
>
> Is there an answer?
> If not, how to achieve that, or anyhow work around the issue?
>
> Side-question: how to define an Oberon equivalent to Pascal's write?
>
>
> Denis
>
> ________________________________
>
> vit esse estrany ☣
>
> spir.wikidot.com
> --
> 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