comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: character literals
Date: Wed, 12 Feb 2014 10:53:24 -0500
Date: 2014-02-12T10:53:24-05:00	[thread overview]
Message-ID: <wccob2ciayz.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 9d08b5d0-012c-4b94-b8b9-ea6e83f2df4f@googlegroups.com

adambeneschan@gmail.com writes:

> On Tuesday, February 11, 2014 2:27:57 PM UTC-8, ag...@drrob1.com wrote:
>> I have been having a difficulty in my code with character literals.
>> 
>> For example
>> 
>>  IF ch in '0' .. '9' THEN

Note to OP:  If you have questions about an error message, it's best to
cut&paste the exact complete compilable code that caused the error,
along with the exact text of the error message.

The above is legal given the right declaration of ch, but you
didn't show that; there are all sorts of reasons the above could
be illegal.

Also look at Ada.Characters.Handling.  You can call the Is_Digit function.

> Finally, the language does have one special rule:
>
>     for I in 0 .. 9 loop
>
> The literals 0 and 9 could be resolved to any integer type, which
> would make this ambiguous since there are normally multiple integer
> types visible in the program (Integer, Long_Integer, Short_Integer,
> maybe types in Interfaces if you "use" that packaged).  But the
> language rules decree that the type will be Integer in that case.
> This is a situation where some programmers might recommend making the
> type Integer explicit.

Like me.  I think the special-case for Integer is a kludge, so I
would write:

    for I in Some_Type range 0 .. 9 loop

One exception:  If I want to say "do this 5 times", I might write:

    for I in 1 .. 5 loop

and there are no references to I in the loop, so its type is irrelevant.

On the other hand, if the type is clear from the bounds, as in

    for I in 1 .. Some_Array'Last - 1 loop

I wouldn't put the type in.

- Bob

  parent reply	other threads:[~2014-02-12 15:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-11 22:27 character literals agent
2014-02-11 22:49 ` J-P. Rosen
2014-02-11 23:45   ` Bill Findlay
2014-02-11 23:49     ` Ludovic Brenta
2014-02-11 23:58       ` adambeneschan
2014-02-11 23:56 ` adambeneschan
2014-02-12  0:18   ` adambeneschan
2014-02-12  1:34     ` agent
2014-02-12  2:03       ` adambeneschan
2014-02-12 12:50         ` agent
2014-02-12  1:30   ` Jeffrey Carter
2014-02-12  1:50     ` adambeneschan
2014-02-12 15:53   ` Robert A Duff [this message]
2014-02-12 17:55     ` J-P. Rosen
2014-02-14 12:39       ` agent
2014-02-14 18:36         ` AdaControl was: " Simon Clubley
2014-02-15  6:26         ` J-P. Rosen
replies disabled

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