Page 1 of 3

Further revision of Oberon-07

Posted: Wed Sep 07, 2011 10:52 pm
by kevinhely
You may be interested to know that Wirth has made further revisions to Oberon-07.

K.

Re: Further revision of Oberon-07

Posted: Thu Sep 08, 2011 1:09 pm
by cfbsoftware
In the last couple of weeks we have been investigating the changes required to conform to the 2011 Revision of the Oberon-07 report and have already implemented one or two in the development version of the compiler. We plan to replace support for the 2008 language definition with the 2011 language definition in Release v4 of Astrobe. Fortunately most of the changes are minor but good improvements. The char / string changes are the ones that will have the most impact on your existing programs. In summary, the changes are:

Data Types
  • The range of values for INTEGER, REAL and LONGREAL are not prescribed.
  • LONGREAL and REAL may be identical
Characters and Strings
  • There is no longer any distinction between a character constant and a string constant containing a single character. Both are enclosed in double-quotes.
  • Single-character strings can be assigned to variables of type CHAR.
  • Single-quotes can no longer be used as an alternative for double-quotes for string constants.
  • Strings can be assigned to any array of characters, provided the number of characters in the string is not greater than that of the array. If it is less, a null character is appended. (i.e. a null character is no longer always present).
  • The character set is a standard character set but is not necessarily Latin-1.
CASE statements
  • CASE labels can be single-character strings. The selector is CHAR.
Standard Functions
  • INCL, EXCL are reintroduced from the original version of Oberon for including / excluding an element in a SET
  • SHORT and LONG are reintroduced for converting LONGREAL to REAL and vice versa.
  • FLOOR can be used with LONGREALs as well as REALs.
  • LSR has been replaced by ROR.
  • ORD can be used with a SET as a parameter
  • ABS can no longer be used with a SET as a parameter
--------------------------------------------------------------------------------

Re: Further revision of Oberon-07

Posted: Sun Sep 11, 2011 4:56 pm
by kevinhely
Hi,

I think the elimination of single quote string delimiters is unfortunate (there is no \" convention for including double quotes in a string).

Is ORD now the way to determine the number of elements in a set? (The report states that it returns the "ordinal", whatever that is.)

K.

Re: Further revision of Oberon-07

Posted: Mon Sep 12, 2011 1:29 pm
by cfbsoftware
I think the elimination of single quote string delimiters is unfortunate
The double-quote character can be specified as the hex char 22X. You would need to replace / insert / append it to a string at runtime. I agree it would be a nuisance but fortunately it is only likely to occur on rare occasions.
(there is no \" convention for including double quotes in a string).
Thankfully not! That 'solution' creates more problems than it solves.
Is ORD now the way to determine the number of elements in a set? (The report states that it returns the "ordinal", whatever that is.)
It is a typecast function i.e. equivalent to SYSTEM.VAL(INTEGER, <set>). You can try it out for yourself as it already exists as an 'undocumented feature' in the current Astrobe compiler.

What I would also find useful is the inverse function for typecasting an INTEGER to a SET. Component Pascal has such a function which is called BITS.

Re: Further revision of Oberon-07

Posted: Wed Sep 14, 2011 11:27 am
by AlexIljin
kevinhely wrote:I think the elimination of single quote string delimiters is unfortunate (there is no \" convention for including double quotes in a string).
I agree, but not because I need to include double quotes in strings very often. AFAIK single quotes as string delimiters were supported ever since Pascal, and I always use them because they are easier to type in the US keyboard layout. You can't type double quotes without pressing the Shift key. I see it as a usability issue.

Re: Further revision of Oberon-07

Posted: Wed Sep 14, 2011 12:38 pm
by cfbsoftware
because they are easier to type in the US keyboard layout
Hmm... I notice that on the German keyboard layout both the single-quote and double-quote are shifted characters...

Perhaps auto-capitalisation of quote characters should be added as an option in Astrobe?

Re: Further revision of Oberon-07

Posted: Fri Sep 16, 2011 9:14 pm
by augustk
Another change is the removal of constant parameters. In Oberon-07/11 non-scalar value parameters can not be assigned to and are passed as constant references. This is a great move I think as the constant parameter was only introduced as an optimization feature.

It is also interesting to note the asymmetry between the types CHAR and String - you can declare a variable or formal parameter of type CHAR but there are no character constants, whereas with the type String there are literals but you cannot declare a variable or formal parameter of that type.

The decision to remove single quotes as a string delimiter may seem drastic at first, but the previous solution of having two alternative quote marks was not sufficient either. Even if you have N different quote marks you still cannot represent a string literal containing all N quote marks. So instead of trying to solve one special case we now have only one way to represent a string literal that will be sufficient in most cases.

Praise to Prof Wirth for finally getting it right.

Re: Further revision of Oberon-07

Posted: Fri Sep 16, 2011 11:16 pm
by cfbsoftware
It is also interesting to note the asymmetry between the types CHAR and String
In theory perhaps but in practice the differences between CHARs and strings have now all but been eliminated. The key point is that now a CHAR and a single character string are compatible. "C" is both a CHAR and an ARRAY 1 OF CHAR depending on the context in which it is used and you can now pass CHAR constants and variables to string (ARRAY OF CHAR) parameters. Some example code which runs in the 2011 revision of Oberon-07 but would not have been been possible in the 2008 revision is:

Code: Select all

MODULE CharString3;

IMPORT Out, Main, Strings;

CONST
  quotes = 22X;

TYPE
  String = ARRAY 255 OF CHAR;
  
VAR
  s: String;
  (* ch: CHAR; Correction: *)
  ch: ARRAY 1 OF CHAR;

PROCEDURE Substitute(newCh, oldCh: CHAR; VAR s: ARRAY OF CHAR);
VAR
  i: INTEGER;
BEGIN
  i := 0;
  WHILE (i < LEN(s)) & (s[i] # 0X) DO 
    IF s[i] = oldCh THEN s[i] := newCh END;
    INC(i)
  END;
END Substitute;


PROCEDURE ProcessEscapes(VAR s: ARRAY OF CHAR);
BEGIN
  (* Replace '\\' with '\' 
             '\q' with '"' 
    This is an exercise for the reader ....
  *) 
END ProcessEscapes;
  

BEGIN

(* Ex.1 *)  
  Out.String("\q = "); Out.Char(quotes); Out.Ln;
  
(* Ex.2 *)   
  s := "\q = ?";
  s[5] := quotes;
  Out.String(s); Out.Ln;

(* Ex.3 *)
  s := "\q = ?";
  Substitute(quotes, "?", s);
  Out.String(s); Out.Ln;

(* Ex.4 *)
  s := "\q = ";
  Strings.Append(quotes, s);
  Out.String(s); Out.Ln;

(* Ex.5 *)
  s := "\q = ";
  ch := quotes;
  Strings.Append(ch, s);
  Out.String(s); Out.Ln;

(* Ex.6 *)
  s := "\\q = \q";
  ProcessEscapes(s);
  Out.String(s); Out.Ln
    
END CharString3.
The resulting output is:

Code: Select all

\q = '
\q = '
\q = '
\q = '
\q = '
\\q = \q
Note: the declaration of Strings.Append is:

Code: Select all

PROCEDURE Append*(src: ARRAY OF CHAR; VAR dest: ARRAY OF CHAR);

Re: Further revision of Oberon-07

Posted: Sat Sep 17, 2011 1:21 am
by augustk
I beg to differ in this case. The expression "C" is a string and nothing else - it is a central property of Oberon-07 that each literal constant (and expression) has a unique and unambiguous type. The phrase "character constant" is not even mentioned in the Oberon-07/11 manual. Where in the manual does it say that character variables are compatible with open character arrays?

It is also worth noting that the string 0X needs special interpretation. According to section three "...a single-character string may be specified by the ordinal number of the character..." and according to section 9.1 "Single-character strings can also be assigned to variables of type CHAR." Since the null character cannot be contained in any string (it is the string terminator) it cannot be a single-character string. It is therefor not even clear if 0X is a valid string. I am a bit confused about this.

Re: Further revision of Oberon-07

Posted: Sat Sep 17, 2011 6:24 am
by cfbsoftware
it is a central property of Oberon-07 that each literal constant (and expression) has a unique and unambiguous type
Maybe so in the 2008 version but not any more. Consider the following valid Oberon-07 (2011) statements:

Code: Select all

VAR
   char: CHAR;
   charString: ARRAY 1 OF CHAR;
   string: ARRAY 2 OF CHAR;

char := "X";
charString := "X"; (* Identical to charString[0] := "X"; *)
string := "X";     (* Identical to string[0] := "X"; string[1] := 0X; *)
string := "XX";    (* Identical to string[0] := "X"; string[1] := "X"; *)

CASE char OF
  "X": .....