Nп/п : 44 из 100
 От   : Maciej Sobczak                      2:5075/128        23 сен 23 13:22:09
 К    : All                                                   23 сен 23 23:25:02
 Тема : Valid attribute and input operations
----------------------------------------------------------------------------------
                                                                                 
@MSGID:
<22930fd1-c7ff-46cf-8c75-892212afa85en@googlegroups.com> 6c1d1bbc
@REPLYADDR Maciej Sobczak
<see.my.homepage@gmail.com>
@REPLYTO 2:5075/128 Maciej Sobczak
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID:
<22930fd1-c7ff-46cf-8c75-892212afa85en@googlegroups.com>
@TZUTC: -0700
@PID: G2/1.0
@TID: FIDOGATE-5.12-ge4e8b94
Hi there,

 I am in the middle of a heated debate with Richard Riehle on
LinkedIn, where we cannot get to terms with regard to the exact semantics of
X`Valid in the context of input operations performed by standard Get
procedure.
In short, consider the following example:

with Ada.Text IO;
with Ada.Integer Text IO;
procedure Is Valid Test is
   X : Integer range 0..200;
begin
   Ada.Text IO.Put("Get an Integer: ");
   Ada.Integer Text IO.Get(X);
   if X`Valid then
      Ada.Text IO.Put Line("The Input is Valid ");
   else
      Ada.Text IO.Put Line("The Input is not Valid ");
   end if;
end Is Valid Test;

When the input is 500, what should be the behavior of this program?
There are two interpretations:

 1. Get is an input operation and can create invalid representations
(as stated in 13.9.2, p.7). Then, the X`Valid test that follows Get(X)
can be used to safely recognize whether the value is in the range or
not. The program should print the second string (from the else branch),
but should not raise any exceptions for this input (500).

 2. Get is not an input operation in the meaning referred to in
13.9.2/7, or is an input, but only for type Integer (and it cannot create
invalid integer representations on typical computers anyway). The X variable
is an actual parameter that has a subtype that is different from the
formal parameter and is subject to conversions when the Get subprogram
exits normally (6.4.1/17,17a). This conversion should raise Constraint Error
for this input (500).

 I have checked the above program on several on-line compilers, all
of them behave according to interpretation 2 above.
Richard claims to get behavior 1 on his compiler.

What is your take on this? Any language lawyers?

Regards,
Maciej Sobczak
--- G2/1.0
 * Origin: usenet.network (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх