Question concerning Arrays
Hi all, In Java one can assign an array value to an array variable like so: int[] A = {0,1,2} Can one write something similar in Oberon? E.
Eric skrev:
Hi all,
In Java one can assign an array value to an array variable like so:
int[] A = {0,1,2}
Can one write something similar in Oberon?
No, there are no array literals/initializers in Oberon, you have to do: VAR A: ARRAY 3 OF INTEGER; ... A[0] := 0; A[1] := 1; A[2] := 2; In this respect, I think maybe the minimalist approach of Oberon went to far. August
There is a project "MathOberon" currently ongoing here at the ETH, where things like that are implemented. There you can define array variables and constant arrays and assign them by value (and much more). As it is work in progress, all I can do right now is asking you to wait a little bit. Felix
Eric skrev:
Hi all,
In Java one can assign an array value to an array variable like so:
int[] A = {0,1,2}
Can one write something similar in Oberon?
No, there are no array literals/initializers in Oberon, you have to do:
VAR A: ARRAY 3 OF INTEGER; ... A[0] := 0; A[1] := 1; A[2] := 2;
In this respect, I think maybe the minimalist approach of Oberon went to far.
August -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Brantley Coile skrev:
A[0] := 0; A[1] := 1; A[2] := 2; In this respect, I think maybe the minimalist approach of Oberon went to far.
That's a matter of taste. As someone who survived PL/1, I'll take Oberon as it is.
Brantley Coile
I agree. I'd be hard pressed to suggest any changes to the meticulous design of Oberon-2. The verbosity that the lack of array literals leads to is a bit frustrating though. August
-----Original Message----- From: oberon-bounces@lists.inf.ethz.ch [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of August Karlstrom Sent: Wednesday, 4 April 2007 4:44 AM To: ETH Oberon and related systems Subject: Re: [Oberon] Question concerning Arrays
Brantley Coile skrev:
A[0] := 0; A[1] := 1; A[2] := 2; In this respect, I think maybe the minimalist approach of Oberon went to far.
That's a matter of taste. As someone who survived PL/1, I'll take Oberon as it is.
Brantley Coile
I agree. I'd be hard pressed to suggest any changes to the meticulous design of Oberon-2. The verbosity that the lack of array literals leads to is a bit frustrating though.
I can imagine some instances where it might be an issue but I haven't personally found it to be a problem in practice. In many cases the values of an array need to be read from an external source (file, registry etc.) anyway so the actual code to populate the array is usually a simple loop rather than a long series of assignment statements. Actually, if your particular example had only a few more elements it would make more sense to write it as: FOR i := 0 TO LEN(A) - 1 DO A[i] := i END; I'd even argue that it might be better to code it that way even for just 3 elements. If there really is some sort of pattern to the values of the array, then the code construct that best illustrates the pattern should be chosen. Another related point often overlooked by programmers with a non-Pascal background is that an entire array can be assigned in a single assignment. At the expense of some memory efficiency, this often leads to better performance e.g. VAR initMatrix, matrix1, matrix2: SomeMatrix; ... ... LoadMatrix(initMatrix); ... ... matrix1 := initMatrix; ... etc. -- Chris Burrows CFB Software http://www.cfbsoftware.com/gpcp
participants (5)
-
August Karlstrom -
Brantley Coile -
Chris Burrows -
Eric -
Felix Friedrich