comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <see.reply.to@maps.futureapps.de>
Subject: Re: not X'Length
Date: Thu, 15 May 2008 22:48:20 +0200
Date: 2008-05-15T22:48:21+02:00	[thread overview]
Message-ID: <482ca195$0$6788$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <954e4cd2-11a9-420b-85c4-7741c429e1b2@c65g2000hsa.googlegroups.com>

christoph.grein@eurocopter.com wrote:
> From RM 4.4 follows that this is equivalent to
> 
> if (not X'Length) in Positive then
> 
> Now Universal_Integer (X'Length is of this type) has no operators, so
> it has to be converted to an appropriate type. This is Integer (or, to
> be very precise, the type of Integer) in this case. But then there is
> no "not" defined for this type. So the compiler is correct.

While the compilers are correct, on the programmer's part the
issue is not that easy to understand in general.
You have demonstrated why this is so. Hence my original
question about programmer expectations regarding improved
compiler's diagnostics in this case.

Apparently GNAT can do better in a similar case,

 if not X'Length in Gotcha then  -- Gotcha a mod type

"warning: not expression should be parenthesized here"

for whatever reason.

The issue is that the compilers are correct but they do
not point at the original programmer mistake. While this isn't
unusual, Ada compilers seem to be very good at pointing to
the real cause.


Suppose you are a willing but naive Ada programmer you had
written (and thought)

IF <L> IN <R> THEN       -- <==*=  IF <E> THEN

o.K., no error. You write

IF not <L> IN <R> THEN   -- <==*= IF not <E> THEN  -- Doh!

and are being told "incompatible types", which is a technically
correct whipping. But the thing that has changed, you thought,
is the addition of negating the original Boolean expression.
You thought. And now there is a type issue?

IF not X'Length IN Positive THEN

(a) it's a precedence thing and
(b) as you demonstrate, it takes several mental indirections
to interpret X'Length correctly
    (b.1) as a value of some unnamed type that
    (b.2) will potentially be of a type that,
          (b.2.*) seen without regard to "IN <R>"
          (b.2.+) seen after "NOT"
is nothing you would have expected. You think,
"How on earth can I apply a Boolean operator to an array length?"

I'm *not* saying the compilers are incorrect.
But maybe they could be a bit more helpful in this case (as in the
second GNAT warning).
This is why I had considered filing an enhancement request, unless
this request is obviously too ambitious. I simply don't know.



  parent reply	other threads:[~2008-05-15 20:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-15  9:19 not X'Length Georg Bauhaus
2008-05-15  9:39 ` christoph.grein
2008-05-15 10:12   ` christoph.grein
2008-05-15 20:48   ` Georg Bauhaus [this message]
2008-05-15 22:20     ` Adam Beneschan
2008-05-16  8:04       ` Manuel Collado
2008-05-16  8:15       ` Georg Bauhaus
2008-05-16 12:52     ` Stephen Leake
replies disabled

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