comp.lang.ada
 help / color / mirror / Atom feed
From: Alex Mentis <asmentis@gmail.com>
Subject: Re: Min/Max attribute makes promises it can't keep
Date: Wed, 28 Apr 2010 03:36:40 -0700 (PDT)
Date: 2010-04-28T03:36:40-07:00	[thread overview]
Message-ID: <880dc0f0-7fff-440d-8aad-6ce745fcfed8@h27g2000yqm.googlegroups.com> (raw)
In-Reply-To: wcczl0o7g13.fsf@shell01.TheWorld.com

On Apr 27, 5:16 pm, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:
> Martin <martin.do...@btopenworld.com> writes:
> >    Put (Positive (Positive'Min(Nat, Pos)));
>
> That works, but I think a qualified expression is better:
>
>    Put (Positive'(Positive'Min(Nat, Pos)));
>
> By the way, there are lots of attributes that work
> like this (use the base subtype).  It's not just Min
> and Max.
>
> - Bob

I think you all missed my point: allowing the programmer to specify a
constraint in situations where the constraint will not be enforced
could cause confusion/error for someone who doesn't have the entire
ARM memorized....

Yes, I know there are ways to force Ada to do the check, like explicit
type conversion and qualified expressions.  That's pretty ugly,
though.  If I already have to put the type in front of the attribute,
why should I have to put the type in front of that again?  As long as
we're posting work-arounds, though, I suppose I would use the
following:

with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;

procedure Main is

   function Min(Value_1, Value_2 : Integer) return Integer renames
Integer'Min;

   Nat : constant Natural := 0;
   Pos : Positive;

begin

   Get (Pos);
   Put (Positive'(Min(Nat, Pos))); -- return a Positive result from
renamed Min else raise a Constraint_Error

end Main;



  parent reply	other threads:[~2010-04-28 10:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-27 19:34 Min/Max attribute makes promises it can't keep Alex Mentis
2010-04-27 20:20 ` Martin
2010-04-27 21:16   ` Robert A Duff
2010-04-27 22:46     ` Randy Brukardt
2010-04-28 10:36     ` Alex Mentis [this message]
2010-04-28 10:58       ` AdaMagica
2010-04-28 11:37         ` Gautier write-only
2010-04-28 11:47           ` AdaMagica
2010-04-28 13:28             ` Martin
2010-04-28 13:41             ` Dmitry A. Kazakov
2010-04-28 14:10               ` Georg Bauhaus
2010-04-28 14:53                 ` Dmitry A. Kazakov
2010-04-28 21:07                   ` Randy Brukardt
2010-04-28 22:17                     ` Dmitry A. Kazakov
2010-05-01  5:42                       ` Randy Brukardt
2010-05-01  6:28                         ` Dmitry A. Kazakov
2010-04-29  4:41                     ` AdaMagica
replies disabled

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