• What is "ARRAY 0 OF something" useful for in Oberon-07

    From Guy T.@21:1/5 to All on Sat Mar 21 12:27:29 2020
    Hello again,

    The Project Oberon compiler allows for a definition as follow:

    VAR a: ARRAY 0 OF CHAR;

    Is there a useful case for defining a zero length array? I can't see any.

    Thanks!

    Guy

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From cfbsoftware@gmail.com@21:1/5 to Guy T. on Sun Mar 22 01:37:12 2020
    On Sunday, March 22, 2020 at 5:57:30 AM UTC+10:30, Guy T. wrote:
    Hello again,

    The Project Oberon compiler allows for a definition as follow:

    VAR a: ARRAY 0 OF CHAR;

    Is there a useful case for defining a zero length array? I can't see any.


    I don't recall ever making use of it myself but I can think of a possible scenario where it could be useful:

    Oberon does not allow optional parameters to procedures. Just suppose you wanted to implement a procedure that generally took an array as a parameter but there were situations where it was not needed. If you could not create a zero array it would not be
    quite as clear to the reader that it is to be ignored. e.g. something like this:

    VAR
    null: ARRAY 0 OF INTEGER;
    values: ARRAY 10 OF INTEGER;
    i: INTEGER;

    PROCEDURE P(i: INTEGER; a: ARRAY OF INTEGER);
    BEGIN
    IF LEN(a) > 0 THEN ...
    END P;

    BEGIN
    P(i, null);
    P(i, values);
    ...
    ...

    P.S. I'm not necessarily recommending this practice ;-)

    Cheers,
    Chris

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From August Karlstrom@21:1/5 to cfbsoftware@gmail.com on Sun Mar 22 15:01:49 2020
    On 2020-03-22 09:37, cfbsoftware@gmail.com wrote:
    P.S. I'm not necessarily recommending this practice ;-)

    To my mind the following sentence from the language report suggests that
    an array can not have length zero:

    "The elements of the array are designated by indices, which are integers between 0 and the length minus 1."

    https://www.miasap.se/obnc/oberon-report.html


    -- August

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)