comp.lang.ada
 help / color / mirror / Atom feed
* Lower bound of result of Ada.Strings.Unbounded.Slice
@ 2000-11-21  0:00 Jeff Carter
  2000-11-22  4:59 ` Robert Dewar
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Carter @ 2000-11-21  0:00 UTC (permalink / raw)


Consider the following program:

with Ada.Strings.Unbounded;
with Ada.Text_Io;

use Ada.Strings.Unbounded;
use Ada.Text_Io;
procedure Slice_Test is
   Line : constant String := "This is a nice long line.";

   U_Line : constant Unbounded_String := To_Unbounded_String (Line);
begin -- Slice_Test
   Put_Line ("Slice (U_Line, 3, 7)'First =>" &
             Integer'Image (Slice (U_Line, 3, 7)'First) &
             "; Slice (U_Line, 3, 7)'Last =>" &
             Integer'Image (Slice (U_Line, 3, 7)'Last) );
end Slice_Test;

Compiler A has 1 and 5 in its output, while compiler B has 3 and 7.

As far as I can tell from the ARM, both results are acceptable. So are
22 and 26.

This makes it difficult to write portable code that uses an index in the
result of Slice to access a position in the whole string. Consistency
across compilers here would be a Good Thing, IMHO. The value of the Low
parameter to Slice would be the better lower bound, I think, since it is
what you get with type String.

Is this something I should submit as a potential AI?

-- 
Jeff Carter
"Nobody expects the Spanish Inquisition!"
Monty Python's Flying Circus




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Lower bound of result of Ada.Strings.Unbounded.Slice
  2000-11-22  4:59 ` Robert Dewar
@ 2000-11-22  0:00   ` Jeff Carter
  2000-11-22  0:00     ` Randy Brukardt
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Carter @ 2000-11-22  0:00 UTC (permalink / raw)


Robert Dewar wrote:
> Always look up existing AI's before submitting a new one :-)

That would be easier if there were some way to search them without
downloading all of them.

The only AI I could find that mentioned Unbounded.Slice is 128, which
contains a comment from Keith Thompson that he disagreed with Bob Duff
saying the lower bound should be 1, and that Robert Dewar also disagreed
with Bob Duff. Perhaps I don't know how to read an AI, but I saw nothing
to indicate that this was a binding interpretation (though I hope I'm
wrong).

> The proper answer is that the slice semantics are to be
> observed (forcing a lower bound of 1 is wrong).

If that's true, can I presume that the current version of GNAT works
this way? The compiler that gave 1 as the lower bound is GNAT 3.13p/Win.

-- 
Jeff Carter
"Hello! Smelly English K...niggets."
Monty Python & the Holy Grail




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Lower bound of result of Ada.Strings.Unbounded.Slice
  2000-11-22  0:00   ` Jeff Carter
@ 2000-11-22  0:00     ` Randy Brukardt
  2000-11-23  0:00       ` Jeff Carter
  0 siblings, 1 reply; 5+ messages in thread
From: Randy Brukardt @ 2000-11-22  0:00 UTC (permalink / raw)


Jeff Carter wrote in message <3A1C4F45.26F41F0D@acm.org>...
>Robert Dewar wrote:
>> Always look up existing AI's before submitting a new one :-)
>
>That would be easier if there were some way to search them without
>downloading all of them.
>
>The only AI I could find that mentioned Unbounded.Slice is 128, which
>contains a comment from Keith Thompson that he disagreed with Bob Duff
>saying the lower bound should be 1, and that Robert Dewar also
disagreed
>with Bob Duff. Perhaps I don't know how to read an AI, but I saw
nothing
>to indicate that this was a binding interpretation (though I hope I'm
>wrong).

The AI itself is part of the corrigendum, but as you say, it has nothing
to say about the lower bound of Slice.

The correct AI to look at is AI-00238. It asks this exact question. You
will note, however, that this is a work item AI which has not yet been
considered by the full ARG. (It wasn't discussed at the recent meeting).
The write-up is based on E-Mail discussion and aan existing
implementation survey.

The e-mail in the appendix is interesting; it is awful long for such a
simple issue!

Anyway, I think it wouldn't be too prudent to depend on any particular
bounds from Slice until this issue is resolved.

                Randy Brukardt, ARG Editor









^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Lower bound of result of Ada.Strings.Unbounded.Slice
  2000-11-21  0:00 Lower bound of result of Ada.Strings.Unbounded.Slice Jeff Carter
@ 2000-11-22  4:59 ` Robert Dewar
  2000-11-22  0:00   ` Jeff Carter
  0 siblings, 1 reply; 5+ messages in thread
From: Robert Dewar @ 2000-11-22  4:59 UTC (permalink / raw)


In article <3A1B087B.D45A8751@acm.org>,
  Jeff Carter <jrcarter@acm.org> wrote:
> Is this something I should submit as a potential AI?

Always look up existing AI's before submitting a new one :-)

The proper answer is that the slice semantics are to be
observed (forcing a lower bound of 1 is wrong).


Sent via Deja.com http://www.deja.com/
Before you buy.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Lower bound of result of Ada.Strings.Unbounded.Slice
  2000-11-22  0:00     ` Randy Brukardt
@ 2000-11-23  0:00       ` Jeff Carter
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff Carter @ 2000-11-23  0:00 UTC (permalink / raw)


Randy Brukardt wrote:
> The correct AI to look at is AI-00238. It asks this exact question. You
> will note, however, that this is a work item AI which has not yet been
> considered by the full ARG. (It wasn't discussed at the recent meeting).
> The write-up is based on E-Mail discussion and aan existing
> implementation survey.

Thanks for pointing this out to me.

> The e-mail in the appendix is interesting; it is awful long for such a
> simple issue!

It certainly is interesting. FWIW, this is the first time I have needed
Slice, and I assumed the same bounds as To_String (U) (Low .. High). I
was using GNAT, so I got bit. Since the ARM has nothing to say on the
bounds, I tested it with another compiler and saw that its results
differed.

> Anyway, I think it wouldn't be too prudent to depend on any particular
> bounds from Slice until this issue is resolved.

I try to avoid compiler dependencies. The work around is fairly straight
forward:

declare
   S : constant String (Low .. High) := Slice (U, Low, High);
begin
   Statements where you would like to use Slice directly
end;

-- 
Jeff Carter
"Hello! Smelly English K...niggets."
Monty Python & the Holy Grail




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-11-23  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-21  0:00 Lower bound of result of Ada.Strings.Unbounded.Slice Jeff Carter
2000-11-22  4:59 ` Robert Dewar
2000-11-22  0:00   ` Jeff Carter
2000-11-22  0:00     ` Randy Brukardt
2000-11-23  0:00       ` Jeff Carter

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