comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Eachus <rieachus@comcast.net>
Subject: Re: how to do things like procedure foo(A: string) is bar: string := A; begin; ...;end;
Date: Mon, 18 Dec 2017 13:14:19 -0800 (PST)
Date: 2017-12-18T13:14:19-08:00	[thread overview]
Message-ID: <c1d88c86-c081-44d0-8022-3c0f995d4ada@googlegroups.com> (raw)
In-Reply-To: <dceffe89-10a1-4a76-b0a3-767e4afcd1a1@googlegroups.com>

On Monday, December 18, 2017 at 10:34:50 AM UTC-5, Mehdi Saada wrote:
 
> Not sure about the constrained formal parameter part. What happens when you call something like
> function FOO(T: String range 5..9) return String;
> with a parameter whose index subtype's bounds are say, 1..4 ? You say it would raise Constraint_Error ? If so I can see the point. There's never too much facultative checks.

Yes, the bounds don't have to match, but the lengths do. (I hope the different lengths were not a typo.)  However, there is another problem.  Way, way back subroutine parameters were changed to eliminate range constraints.  You can say:

subtype PS is String range(1..4);
subtype TS is String range(5..9);
procedure Foo(T: TS);
...
Foo(PS); --raises Constraint_Error
Foo('X' & PS); -- OK.

But:
procedure Foo(T: String range 5..9)...  -- will fail at compile time.

Why were formal parameters changed to eliminate (syntatic) constraints?  They didn't accomplish much other than to confuse users.  You can get the same effect by using explicit subtype declarations--as above--if you want it.  Making things explicit helps both reader and programmer in those cases.


  parent reply	other threads:[~2017-12-18 21:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-16 20:56 how to do things like procedure foo(A: string) is bar: string := A; begin; ...;end; Mehdi Saada
2017-12-16 21:49 ` Jeffrey R. Carter
2017-12-17 12:40   ` Mehdi Saada
2017-12-17 13:25     ` Jere
2017-12-17 13:49       ` Jere
2017-12-17 13:51     ` Jeffrey R. Carter
2017-12-18 22:22     ` Randy Brukardt
2017-12-18  6:39 ` Robert Eachus
2017-12-18 15:34   ` Mehdi Saada
2017-12-18 17:31     ` Anh Vo
2017-12-18 21:14     ` Robert Eachus [this message]
2017-12-19 22:52   ` Robert Eachus
replies disabled

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