[Oberon] Compiler behaviour for a32 := a8

Hans Klaver hklaver at dds.nl
Mon Feb 1 10:04:54 CET 2021


The recent discussions about strings and the OR compiler and how one should interpret the language report reminded me of a question that has puzzled me for some time now.

In the change from Oberon (1990) to Oberon-07 the standard procedure COPY(src, dst) was discarded by NW and the type check of the assignment operator := for strings and character arrays was changed somewhat.

In Oberon (1990) str2 := str1 was only possible if str1 and str2 were of the *same* type; and COPY could be used if the types were different, truncating a string if necessary.

In Oberon-07 str2 := str1 also is possible if s1 and s2 are of *different* types, provided their lengths are *equal*. At least that is how Wirth's OR compiler behaves; at least one compiler (OBNC) still precludes assignment if str1 and str2 are of different types.
 
Now, in Wirth's document 'Differences between Revised Oberon and Oberon' (https://people.inf.ethz.ch/wirth/Oberon/Oberon07.pdf) under '4. Assignment of arrays and records' one can read: 
'(...) But now we handle array and record assignments just like other assignments, writing dst := src, and discard the COPY procedure. The destination array must not be shorter than the source array. (...)'

So I would expect that something like the following should be possible:

   ... 
   VAR
     a8:  ARRAY 8 OF CHAR;
     a32: ARRAY 32 OF CHAR;
   BEGIN
     ...
     a32 := a8;  (* error: illegal assignment *)

But unfortunately this is not possible with the current implementation of the Oberon-07 language. So now we have to use a Strings procedure to get this done:
   Strings.Copy(a8, a32)  (* equivalent to:  a32 := ""; Strings.Insert(a8, 0, a32) *)

Whereas the following *is* possible when using the OR compiler, which I would regard as not in the spirit of the Oberon language (and that's why I think OBNC has the proper behaviour):
   
   TYPE
     Man      = ARRAY 32 OF CHAR;
     Woman    = ARRAY 32 OF CHAR;
     NoGender = ARRAY 32 OF CHAR;
   VAR
     m: Man;
     n: NoGender;
     w: Woman;
   BEGIN
     ...
     m := w;  (* OR: no error;  OBNC: incompatible types in assignment *)
     n := m;  (* OR: no error;  OBNC: incompatible types in assignment *)


In my view a32 := a8 should be allowed and m := w or n := m not!

What do you think?


Hans Klaver


    
 




More information about the Oberon mailing list