* loop on character
@ 2008-10-08 21:26 Bernd Specht
2008-10-08 21:42 ` Adam Beneschan
2008-10-08 22:50 ` Robert A Duff
0 siblings, 2 replies; 6+ messages in thread
From: Bernd Specht @ 2008-10-08 21:26 UTC (permalink / raw)
Although I've worked with Ada for a few years, I've got a problem now that
looks a bit like a beginners problem to me. Can someone help me?
I wrote a statement like this:
for c in '0'..'9'
loop
...
end loop;
and the compiler says "ambigous character literals (could be
Wide_Character)"
what would be the correct way to write this?
Ok, I can declare some variables first, but I think there must be a better
way.
low : Character := '0';
high : Character := '9';
for c in low .. high
loop
...
end loop;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: loop on character
2008-10-08 21:26 loop on character Bernd Specht
@ 2008-10-08 21:42 ` Adam Beneschan
2008-10-08 22:45 ` Jeffrey R. Carter
2008-10-09 19:13 ` Jerry
2008-10-08 22:50 ` Robert A Duff
1 sibling, 2 replies; 6+ messages in thread
From: Adam Beneschan @ 2008-10-08 21:42 UTC (permalink / raw)
On Oct 8, 2:26 pm, Bernd.Spe...@gmx.com (Bernd Specht) wrote:
> Although I've worked with Ada for a few years, I've got a problem now that
> looks a bit like a beginners problem to me. Can someone help me?
>
> I wrote a statement like this:
>
> for c in '0'..'9'
> loop
> ...
> end loop;
>
> and the compiler says "ambigous character literals (could be
> Wide_Character)"
>
> what would be the correct way to write this?
for C in Character range '0' .. '9' loop
-- Adam
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: loop on character
2008-10-08 21:42 ` Adam Beneschan
@ 2008-10-08 22:45 ` Jeffrey R. Carter
2008-10-09 19:13 ` Jerry
1 sibling, 0 replies; 6+ messages in thread
From: Jeffrey R. Carter @ 2008-10-08 22:45 UTC (permalink / raw)
Adam Beneschan wrote:
>
> for C in Character range '0' .. '9' loop
You can also do
for C in Character'('0') .. '9' loop
which gives an interesting, if difficult to read, sequence of 3 apostrophes
separated by other characters.
As long as the compiler knows the type of at least one of the literals it will
be happy. As the OP pointed out, making at least one of them an object will do
it. If he wants the literals in the loop statement, "Character range" would be
my choice.
--
Jeff Carter
"Hello! Smelly English K...niggets."
Monty Python & the Holy Grail
08
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: loop on character
2008-10-08 21:42 ` Adam Beneschan
2008-10-08 22:45 ` Jeffrey R. Carter
@ 2008-10-09 19:13 ` Jerry
2008-10-09 22:18 ` Adam Beneschan
1 sibling, 1 reply; 6+ messages in thread
From: Jerry @ 2008-10-09 19:13 UTC (permalink / raw)
On Oct 8, 2:42 pm, Adam Beneschan <a...@irvine.com> wrote:
>
> for C in Character range '0' .. '9' loop
>
> -- Adam
Does this construction have a name? By "this construction" I mean the
presence of Character in the for statement. Presumably other types can
be included at that position.
The Perpetual Newb,
Jerry
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: loop on character
2008-10-09 19:13 ` Jerry
@ 2008-10-09 22:18 ` Adam Beneschan
0 siblings, 0 replies; 6+ messages in thread
From: Adam Beneschan @ 2008-10-09 22:18 UTC (permalink / raw)
On Oct 9, 12:13 pm, Jerry <lancebo...@qwest.net> wrote:
> On Oct 8, 2:42 pm, Adam Beneschan <a...@irvine.com> wrote:
>
>
>
> > for C in Character range '0' .. '9' loop
>
> > -- Adam
>
> Does this construction have a name? By "this construction" I mean the
> presence of Character in the for statement.
It doesn't quite have a name of its own. "Character range '0'..'9'"
is a discrete_subtype_definition, but it would still be that without
the type name. Going further, this form of
discrete_subtype_definition is a discrete_subtype_indication, which is
just a kind of subtype_indication, which is a type or subtype name
optionally followed by a constraint. See 5.5(4), 3.6(6), 3.2.2(3).
Note the *optionally*: you can write a loop providing just a type
(subtype) name without the range constraint---see Bob's response for
an example.
> Presumably other types can
> be included at that position.
Yes, but only discrete types (integer or enumeration).
-- Adam
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: loop on character
2008-10-08 21:26 loop on character Bernd Specht
2008-10-08 21:42 ` Adam Beneschan
@ 2008-10-08 22:50 ` Robert A Duff
1 sibling, 0 replies; 6+ messages in thread
From: Robert A Duff @ 2008-10-08 22:50 UTC (permalink / raw)
Bernd.Specht@gmx.com (Bernd Specht) writes:
> low : Character := '0';
> high : Character := '9';
>
> for c in low .. high
> loop
> ...
> end loop;
If you do it that way, low and high should be constant.
Others have suggested "for C in Character...",
which is probably what you want.
Here's another variation:
subtype Digit is Character range '0'..'9';
for C in Digit loop...
- Bob
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-10-09 22:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-08 21:26 loop on character Bernd Specht
2008-10-08 21:42 ` Adam Beneschan
2008-10-08 22:45 ` Jeffrey R. Carter
2008-10-09 19:13 ` Jerry
2008-10-09 22:18 ` Adam Beneschan
2008-10-08 22:50 ` Robert A Duff
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox