* I wish I could ...
@ 2004-09-16 18:11 Björn Persson
2004-09-16 18:20 ` Frank J. Lhota
2004-09-17 7:28 ` Jeffrey Carter
0 siblings, 2 replies; 4+ messages in thread
From: Björn Persson @ 2004-09-16 18:11 UTC (permalink / raw)
Right now I'm writing code like this in several places:
case Going is
when Forward =>
for Pos in 1 .. Source.Last loop
if Source.Reference.all (Pos) /= Character'Pos(Space) then
return Pos;
end if;
end loop;
when Backward =>
for Pos in reverse 1 .. Source.Last loop
if Source.Reference.all (Pos) /= Character'Pos(Space) then
return Pos;
end if;
end loop;
end case;
I wish I could just write:
for Pos in Going 1 .. Source.Last loop
if Source.Reference.all (Pos) /= Character'Pos(Space) then
return Pos;
end if;
end loop;
--
Björn Persson PGP key A88682FD
omb jor ers @sv ge.
r o.b n.p son eri nu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: I wish I could ...
2004-09-16 18:11 I wish I could Björn Persson
@ 2004-09-16 18:20 ` Frank J. Lhota
2004-09-16 19:04 ` Björn Persson
2004-09-17 7:28 ` Jeffrey Carter
1 sibling, 1 reply; 4+ messages in thread
From: Frank J. Lhota @ 2004-09-16 18:20 UTC (permalink / raw)
How about this:
declare
Direction_For : constant array ( Going_Type ) of
Ada.Strings.Direction :=
(
Forward => Ada.Strings.Forward,
Backward => Ada.Strings.Backward
);
begin
return Ada.Strings.Fixed.Index
(
Source => Source.Reference( 1 .. Source.Last ),
Mapping => String'( 1 => Space ),
Going => Direction_For( Going )
);
end;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: I wish I could ...
2004-09-16 18:20 ` Frank J. Lhota
@ 2004-09-16 19:04 ` Björn Persson
0 siblings, 0 replies; 4+ messages in thread
From: Björn Persson @ 2004-09-16 19:04 UTC (permalink / raw)
I can't call Index because I'm essentially writing Index (although this
particular example was from Index_Non_Blank). I'm writing this for my
EAstrings library (which is part of AdaCL). EAstrings works like
Ada.Strings.Unbounded, but it keeps track of how the strings are encoded
and transcodes them when necessary.
All I wanted to say was that it would be nice to be able to parameterize
the "reverse" in a for loop.
--
Björn Persson PGP key A88682FD
omb jor ers @sv ge.
r o.b n.p son eri nu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: I wish I could ...
2004-09-16 18:11 I wish I could Björn Persson
2004-09-16 18:20 ` Frank J. Lhota
@ 2004-09-17 7:28 ` Jeffrey Carter
1 sibling, 0 replies; 4+ messages in thread
From: Jeffrey Carter @ 2004-09-17 7:28 UTC (permalink / raw)
Bj�rn Persson wrote:
> Right now I'm writing code like this in several places:
>
> case Going is
> when Forward =>
> for Pos in 1 .. Source.Last loop
> if Source.Reference.all (Pos) /= Character'Pos(Space) then
> return Pos;
> end if;
> end loop;
> when Backward =>
> for Pos in reverse 1 .. Source.Last loop
> if Source.Reference.all (Pos) /= Character'Pos(Space) then
> return Pos;
> end if;
> end loop;
> end case;
This looks like a function:
function Find_Other (Source : Whatever; Item : Whatever_Else)
return Thingy;
Where
Whatever is the type of Source in your code
Whatever_Else is the type of Source.Reference (Pos)
Thingy is the type of Pos
You would also want a similar function that uses "=" rather than "/=":
function Find_Equal (Source : Whatever; Item : Whatever_Else)
return Thingy;
Then all the cases where you're writing code like your example would be
replaced by a call to one of these functions.
It's probably more complicated than that.
--
Jeff Carter
"The time has come to act, and act fast. I'm leaving."
Blazing Saddles
36
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-09-17 7:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-16 18:11 I wish I could Björn Persson
2004-09-16 18:20 ` Frank J. Lhota
2004-09-16 19:04 ` Björn Persson
2004-09-17 7:28 ` Jeffrey Carter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox