[Oberon] concrete use of open array

spir denis.spir at gmail.com
Thu Jun 24 17:49:52 MEST 2010


Hello,


I start to get a feeling of Oberon's style (I guess). Seems it requires programmers to build their toolkit, even for very basic, everyday, all-purpose, little tiny tasks (even more than eg Lua, which reputation reads "DIY"). Comments?
Some details still escape my understanding, esp. around open arrays -- again.


-1- form of actual parameter

Since one cannot have a VAR of open array type, what is the actual form of an open array parameter, in the call expression?
I tried the "[...]" format used in some Pascal dialects to express open array constants, but it is refused.
Side-question: is there a literal notation for arrays? for records? (eg like pascal consts, or var initialisation)


-2- COPY vs assignment

The following is accepted by obc but refused by oo2c [EDIT: the opposite, in fact!]. Note that t1 & t2 share a unique & named type. In the latter case, I need to use COPY instead of :=.

MODULE trial;
TYPE ToChars = POINTER TO ARRAY OF CHAR;
VAR	i	: INTEGER;
	t1,t2	: ToChars;
BEGIN
	NEW(t1,3) ; NEW(t2,3);
	FOR i := 0 TO 2 DO t1[i] := CHR(97+i) END; t2[3] := 0X;
	t2 := t1;	(* COPY(t1^,t2^); *)
	(* output routine *)
END trial.

But COPY removes the last element by replacing it with 0X, whatever lies there in the source array. My use case is a flexible array, of which a char sequence is only a particuliar case, which holds a 'size field' (so that getting the size does not require sequence traversal). Also, arrays of chars are commonly used as byte sequences. (Even more on Oberon since there is no BYTE?)
Is there a way to make assignement work between all kinfs of open arrays?


-2- size & copy

Assignment/copy between arrays of different sizes does not seems to be possible, or at least I could not have it work (neither is the case where dest >source, nore the opposite). About COPY, the report says the dest if truncated if necessary, but even this does not work with the compilers I use. Is there a way to express:
    a2 := a1[i..j];
    a2[i..j] := a1;
?


-4- allocation

Say I'm writing a func returning the indices of occurrences of a given element in a collection. I guess the only possible return type is a pointer to an open array. Correct? But how to allocate it (NEW(indices,size)), since its size is also a result of the process (collection traversal)?
The only solution I found is two traverse twice ;-): once to count and then allocate, once to feed the array.


off-topic:
* is it possible to rename imported procs (eg "Write := Out.String" :-)?
* alternatives to "(**)" such as "{}" or "//"? My editor deals badly with "(**)", transforming comments into visual pollution; and not permitting comment-in/out toggling.


Denis
________________________________

vit esse estrany ☣

spir.wikidot.com


More information about the Oberon mailing list