From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,aaabba5db6b5df34 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!h27g2000yqm.googlegroups.com!not-for-mail From: Alex Mentis Newsgroups: comp.lang.ada Subject: Re: Min/Max attribute makes promises it can't keep Date: Wed, 28 Apr 2010 03:36:40 -0700 (PDT) Organization: http://groups.google.com Message-ID: <880dc0f0-7fff-440d-8aad-6ce745fcfed8@h27g2000yqm.googlegroups.com> References: <98b7e6f2-32ed-465c-9a52-541b7878ca86@y17g2000yqd.googlegroups.com> <9b17e781-f46a-4384-8809-b16602d10114@y30g2000yqh.googlegroups.com> NNTP-Posting-Host: 76.15.10.164 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1272451000 24634 127.0.0.1 (28 Apr 2010 10:36:40 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 28 Apr 2010 10:36:40 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h27g2000yqm.googlegroups.com; posting-host=76.15.10.164; posting-account=CedHywoAAAAcVQwJt5x8TeyAwJA5ElaR User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729; .NET4.0E),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:11223 Date: 2010-04-28T03:36:40-07:00 List-Id: On Apr 27, 5:16=A0pm, Robert A Duff wrote: > Martin writes: > > =A0 =A0Put (Positive (Positive'Min(Nat, Pos))); > > That works, but I think a qualified expression is better: > > =A0 =A0Put (Positive'(Positive'Min(Nat, Pos))); > > By the way, there are lots of attributes that work > like this (use the base subtype). =A0It'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 :=3D 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;