comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Range constraints on subprogram parameters?
Date: Fri, 30 Sep 2005 20:07:25 -0500
Date: 2005-09-30T20:07:25-05:00	[thread overview]
Message-ID: <l5qdnVOvLLT2faDeRVn-ow@megapath.net> (raw)
In-Reply-To: yi4%e.5290$oc.213@newsread2.news.pas.earthlink.net

"Jeffrey R. Carter" <spam@spam.com> wrote in message
news:yi4%e.5290$oc.213@newsread2.news.pas.earthlink.net...
> Bobby D. Bryant wrote:
> > Yes, that's what I was wanting.
> >
> > It occurs to me in retrospect that it would be problematic from a
> > language design perspective, since it would be impossible to enforce
> > at compile time.
>
> It doesn't have to be enforceable at compile time, since subtype
constraints
> don't have to be static:
>
> procedure Outer (Max : in Positive) is
>     subtype Num is Positive range 1 .. Max;
>
>     procedure Inner (X : in Num) is
>
> is perfectly legal.
>
> It mostly depends on where the subprogram is declared compared to where
the
> constraints are known.

Actually, Bobby was correct. The reason you can't have subtype constraints
in a parameter declaration is because they aren't required to be static. The
problem is one of conformance when you have separate specifications and
bodies. If F is an integer-returning function that returns 1 the first time
it is called, 2 the second tine, and so on, what is the range of the
parameter P?

    procedure Ugh (P : in Integer range 0 .. F); -- F = 1.

    Obj : constant Integer := F; -- Call on F = 2.

    procedure Ugh (P : in Integer range 0 .. F) is -- F = 3.
       ...

This is why Ada 200Y allows null exclusions in parameters: because they
always have to be static. We talked a bit aboult allowing static constraints
in subprogram parameter declarations, but didn't do it because that seemed
even more arbitrary than not allowing them at all.

Note that declaring the subtype explicitly (and separately) doesn't have
this problem.

                         Randy.






  reply	other threads:[~2005-10-01  1:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-28 20:00 Range constraints on subprogram parameters? Bobby D. Bryant
2005-09-29  5:39 ` Jeffrey R. Carter
2005-09-29  8:30   ` Peter Hermann
2005-09-29  9:06     ` Martin Dowie
2005-09-29 18:16     ` Jeffrey R. Carter
2005-09-30  2:23     ` Bobby D. Bryant
2005-09-30  5:46       ` Jeffrey R. Carter
2005-10-01  1:07         ` Randy Brukardt [this message]
2005-10-01  3:50           ` Jeffrey R. Carter
2005-10-01 14:36           ` Robert A Duff
2005-10-01 14:41             ` Robert A Duff
2005-09-30  2:24   ` Bobby D. Bryant
replies disabled

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