comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: DECAda/VMS - calling GETJPI
Date: 1996/06/05
Date: 1996-06-05T00:00:00+00:00	[thread overview]
Message-ID: <DsJAtM.949@world.std.com> (raw)
In-Reply-To: 4p32m3$51g@mulga.cs.mu.OZ.AU


In article <4p32m3$51g@mulga.cs.mu.OZ.AU>,
Fergus Henderson <fjh@mundook.cs.mu.OZ.AU> wrote:
>It would be helpful if someone were to give a brief explanation
>of the arguments in favour of this design decision.

I can't remember all the details of the arguments at the time.

I think part of it was that people thought the old rules were confusing.
People felt that since -1 is simply not a value of the modular type,
that it ought to raise C_E on conversion.  Arithmetic purely within the
modular type is different -- you can never get the value -1 in the first
place.

One might like type conversions to be reversible.

    I: Integer := -1;
    subtype S1 is Integer range 0..255;
    X: S1 := 255;
    subtype S2 is Integer range -128..127;
    Y: S2 := -1;
    type M is mod 256;
    Z: M;

Now converting 255 of type M to type Integer produces 255, clearly,
and not -1.  So:

    Z := M(I); -- Contraint_Error happens here, but if it didn't, then
    I := Integer(Z); -- ...now I has changed its value, which some
                     -- might consider strange.

    Z := M(Y); -- OK.
    X := Integer(Z); -- Here, X has the same value it did before.
    
    Z := M(X); -- Contraint_Error happens here, but if it didn't, then
    Y := Integer(Z); -- ...you'd get Constraint_Error here.

Whether this would confuse is, I suppose, a matter of opinion.

Now, consider:

    procedure P(Param: in out M) is
    begin
        null;
    end P;

    I: Integer := -1;
    
    P(M(I));

Here, I is converted to type M before the call, and converted back to
type Integer after the call.  It might seem strange for a procedure
containing just a null statement to modify its parameter (changing -1 to
255).  (On the other hand, floating point types have the same trouble.)

In other cases, a call to P would raise Constraint_Error while trying to
convert back to the integer type.

Consider also modular-to-modular conversions.  E.g.:

    type M1 is mod 4;
    type M2 is mod 3;

Now, should converting from M1 to M2 and back to M1 change the value?
Or is it better to consider it an error when the conversion is not
reversible (that is, when the original value is 3)?

One final example:

    type T is range -1..100;
    type M is mod 2**32;

If we convert the value 101 of type M to SUBtype T, it will clearly
raise Constraint_Error.  Should converting 2**32-1 do the same, or
should it return -1?

- Bob




  reply	other threads:[~1996-06-05  0:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-06-03  0:00 DECAda/VMS - calling GETJPI Alan Paterson
1996-06-03  0:00 ` Stuart Palin
1996-06-03  0:00   ` Michael F Brenner
1996-06-03  0:00     ` Robert Dewar
1996-06-04  0:00       ` Ken Garlington
1996-06-06  0:00         ` Robert Dewar
1996-06-04  0:00       ` Michael F Brenner
1996-06-04  0:00         ` Robert Dewar
1996-06-04  0:00           ` Michael F Brenner
1996-06-04  0:00             ` Robert Dewar
1996-06-04  0:00             ` Robert Dewar
1996-06-05  0:00               ` Fergus Henderson
1996-06-05  0:00                 ` Robert A Duff [this message]
1996-06-05  0:00               ` Robert A Duff
1996-06-05  0:00                 ` Robert Dewar
1996-06-05  0:00               ` Wraparound on modular conversion (was: DECAda/VMS - calling GETJPI) Tucker Taft
1996-06-05  0:00                 ` Robert Dewar
1996-06-05  0:00             ` DECAda/VMS - calling GETJPI Adam Beneschan
1996-06-07  0:00               ` Norman H. Cohen
1996-06-11  0:00                 ` Adam Beneschan
1996-06-03  0:00 ` Mats Weber
1996-06-03  0:00 ` Ken Garlington
  -- strict thread matches above, loose matches on Subject: below --
1996-06-06  0:00 George Haddad
1996-06-07  0:00 ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox