• Is this an error in compiler

    From reinert@21:1/5 to All on Sun Sep 11 00:19:05 2022
    Hello,

    I tried alire with the latest version of the compiler (I believe) and I got trouble
    compiling this program (which I here have reduced just to communicate my point - i.e. the program has no other meaning here):
    --------------------------------------------------------------------------------------------
    with Ada.Strings.Fixed; use Ada.Strings.Fixed;
    with Ada.Exceptions;
    with Ada.Text_IO; use Ada.Text_IO;

    procedure c0a is

    subtype String_1 is String (1 .. <>);

    package cpros is
    cfe0,cfe1,cfe2 : exception;
    generic
    with procedure execute_command1 (command1 : String);
    procedure cpros0
    (file1 : in Ada.Text_IO.File_Type; command0 : String := "");
    end cpros;

    package body cpros is

    procedure cpros0 (file1 : in Ada.Text_IO.File_Type; command0 : String := "")
    is
    begin
    declare
    function rep1 (str0 : String_1) return String is
    i : constant Natural := Index (str0, "$");
    begin
    return str0 when i = 0;
    raise cfe2 with "(wrong use of '$')" when i = str0'Last; -- a
    -- if i = str0'Last then -- b
    -- raise cfe2 with "(wrong use of '$')"; -- b
    -- end if; -- b
    return "aaa";
    end rep1;
    str0 : constant String := rep1 (Get_Line (file1));
    begin
    null;
    end;
    end cpros0;
    end cpros;

    procedure execute_command1 (str : String) is
    begin
    null;
    end execute_command1;

    procedure cpros1 is new cpros.cpros0 (execute_command1 => execute_command1);

    begin
    null;
    end c0a; -----------------------------------------------------------------------------------------------
    This goes through when I compile it.

    However, if I uncomment the "a" line and comment out the "b" line (see code above), then I get the error message:

    c0a.adb:45:04: error: instantiation error at line 27
    c0a.adb:45:04: error: "cfe2" is not visible
    c0a.adb:45:04: error: instantiation error at line 27
    c0a.adb:45:04: error: non-visible declaration at line 10

    Have you the same experience?

    reinert

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Simon Wright@21:1/5 to reinert on Sun Sep 11 09:10:12 2022
    reinert <reinkor@gmail.com> writes:

    (4 times!!!!)

    However, if I uncomment the "a" line and comment out the "b" line (see
    code above), then I get the error message:

    c0a.adb:45:04: error: instantiation error at line 27
    c0a.adb:45:04: error: "cfe2" is not visible
    c0a.adb:45:04: error: instantiation error at line 27
    c0a.adb:45:04: error: non-visible declaration at line 10

    Have you the same experience?

    You have the conditions the wrong way round: if the 'a' line is
    commented out and the 'b' lines are uncommented, the compilation
    succeeds; the source as presented (and if compiled with -gnatX) fails in
    the way you state.

    And, yes, it's a compiler error.

    I have to say these conditional constructs strike me as regrettable
    Perl-isms, and reduce clarity:

    return foo when blah;
    raise baz when quux;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From reinert@21:1/5 to All on Sun Sep 11 03:52:05 2022
    søndag 11. september 2022 kl. 10:10:19 UTC+2 skrev Simon Wright:
    reinert <rei...@gmail.com> writes:

    (4 times!!!!)

    4 times?

    The google system must have been too quick to store/spread my message before me deleting.
    It seems not to consider dysleksi :-)

    reinert

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeffrey R.Carter@21:1/5 to Simon Wright on Sun Sep 11 14:30:11 2022
    On 2022-09-11 10:10, Simon Wright wrote:

    I have to say these conditional constructs strike me as regrettable Perl-isms, and reduce clarity:

    return foo when blah;
    raise baz when quux;

    I presume you never use

    exit Name when Condition;

    since it must reduce clarity as well.

    I suggested these constructs for Ada 9X. They were rejected because you could get the same functionality with an if statement, and the ARG had more important things to spend their time on. I guess the ARG's workload must have decreased.

    --
    Jeff Carter
    "Sheriff murdered, crops burned, stores looted,
    people stampeded, and cattle raped."
    Blazing Saddles
    35

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to Jeffrey R.Carter on Sun Sep 11 14:59:25 2022
    On 2022-09-11 14:30, Jeffrey R.Carter wrote:
    On 2022-09-11 10:10, Simon Wright wrote:

    I have to say these conditional constructs strike me as regrettable
    Perl-isms, and reduce clarity:

        return foo when blah;
        raise baz when quux;

    I presume you never use

    exit Name when Condition;

    since it must reduce clarity as well.

    I suggested these constructs for Ada 9X. They were rejected because you
    could get the same functionality with an if statement, and the ARG had
    more important things to spend their time on. I guess the ARG's workload
    must have decreased.

    And the evaluation order of the return value vs the condition? E.g. in

    return Boolean'Input (Stream) when Boolean'Input (Stream);

    There is no issue with exit-when of course. Return and, even, raise (as
    you can have an expressions there with Exception_Occurrence type) look problematic.

    I would expect the condition evaluated first, but that is kind of
    "German" way of reading texts... 😂

    --
    Regards,
    Dmitry A. Kazakov
    http://www.dmitry-kazakov.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Oliver Kellogg@21:1/5 to Simon Wright on Sun Sep 11 08:14:50 2022
    On Sunday, September 11, 2022 at 10:10:19 AM UTC+2, Simon Wright wrote:
    reinert <rei...@gmail.com> writes:
    [...]
    I have to say these conditional constructs strike me as regrettable Perl-isms, and reduce clarity:

    return foo when blah;
    raise baz when quux;

    +1 on that.
    On the other hand,

    blah and return foo;
    quux and raise baz;

    would make more sense to me.
    Not that I am proposing it, IMO Ada already has way too many extensions.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Niklas Holsti@21:1/5 to Jeffrey R.Carter on Sun Sep 11 17:44:13 2022
    On 2022-09-11 15:30, Jeffrey R.Carter wrote:
    On 2022-09-11 10:10, Simon Wright wrote:

    I have to say these conditional constructs strike me as regrettable
    Perl-isms, and reduce clarity:

        return foo when blah;
        raise baz when quux;

    I presume you never use

    exit Name when Condition;

    since it must reduce clarity as well.

    I suggested these constructs for Ada 9X. They were rejected because you
    could get the same functionality with an if statement, and the ARG had
    more important things to spend their time on. I guess the ARG's workload
    must have decreased.


    I don't find these "raise .. when" or "return .. when" constructs in the
    Ada 2022 RM draft, so I don't think the ARG has adopted them (yet). I
    suspect they are GNAT extensions, as is the ability to make a subtype of
    String with a fixed lower index bound of 1 but an unconstrained upper
    bound (1 .. <>), as also done in the OP's code.

    I would not use these non-standard GNAT extensions, as long as GNAT is
    not the only Ada compiler in the world, which it fortunately isn't.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeffrey R.Carter@21:1/5 to Niklas Holsti on Sun Sep 11 17:47:21 2022
    On 2022-09-11 16:44, Niklas Holsti wrote:

    I don't find these "raise .. when" or "return .. when" constructs in the Ada 2022 RM draft, so I don't think the ARG has adopted them (yet). I suspect they
    are GNAT extensions, as is the ability to make a subtype of String with a fixed
    lower index bound of 1 but an unconstrained upper bound (1 .. <>), as also done
    in the OP's code.

    Sorry, I didn't realize AdaCore was distributing GNAT for non-Ada.

    I would not use these non-standard GNAT extensions, as long as GNAT is not the
    only Ada compiler in the world, which it fortunately isn't.

    I won't even use the Ada-2X features until it's supported by multiple compilers.

    --
    Jeff Carter
    "Sheriff murdered, crops burned, stores looted,
    people stampeded, and cattle raped."
    Blazing Saddles
    35

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From reinert@21:1/5 to All on Sun Sep 11 09:47:26 2022
    Could the result of

    if function1 and function2 then ....

    depend on the order of evaluation ( in some rare situations when f.eks. function2 affects the outcome from function1)?

    reinert

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to reinert on Sun Sep 11 19:18:24 2022
    On 2022-09-11 18:47, reinert wrote:
    Could the result of

    if function1 and function2 then ....

    depend on the order of evaluation ( in some rare situations when f.eks. function2 affects the outcome from function1)?

    The order is only one half of the problem. Another one is eager
    evaluation. Both function1 and function2 are guaranteed to be evaluated
    in absence of exceptions.

    Short-circuit operators are meant to enforce both the order of
    evaluation and laziness of the second term:

    if function1 and then function2 then ....

    --
    Regards,
    Dmitry A. Kazakov
    http://www.dmitry-kazakov.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Simon Wright@21:1/5 to Niklas Holsti on Mon Sep 12 08:05:18 2022
    Niklas Holsti <niklas.holsti@tidorum.invalid> writes:

    I don't find these "raise .. when" or "return .. when" constructs in
    the Ada 2022 RM draft, so I don't think the ARG has adopted them
    (yet). I suspect they are GNAT extensions, as is the ability to make a subtype of String with a fixed lower index bound of 1 but an
    unconstrained upper bound (1 .. <>), as also done in the OP's code.

    Indeed.

    c0a.adb:7:37: error: fixed-lower-bound array is a GNAT specific extension
    c0a.adb:7:37: error: unit must be compiled with -gnatX switch
    c0a.adb:26:28: error: return when statement is a GNAT specific extension
    c0a.adb:26:28: error: unit must be compiled with -gnatX switch
    c0a.adb:27:59: error: raise when statement is a GNAT specific extension
    c0a.adb:27:59: error: unit must be compiled with -gnatX switch

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