comp.lang.ada
 help / color / mirror / Atom feed
From: "Markus Schöpflin" <no.spam@spam.spam>
Subject: Surprising behaviour of strings.fixed.overwrite
Date: Wed, 12 Nov 2014 11:49:29 +0100
Date: 2014-11-12T11:49:29+01:00	[thread overview]
Message-ID: <m3vdvn$uu$1@speranza.aioe.org> (raw)

Given the following Ada program:

---%<---
with TEXT_IO;
with ADA.STRINGS;
with ADA.STRINGS.FIXED;

procedure TEST
is
    S : STRING(1 .. 6);
begin
    S := "@@@@@@";
    ADA.STRINGS.FIXED.OVERWRITE (S, S'First + 5, "56", ADA.STRINGS.LEFT);
    TEXT_IO.PUT_LINE (S);

    S := "@@@@@@";
    ADA.STRINGS.FIXED.OVERWRITE (S, S'First + 5, "56", ADA.STRINGS.RIGHT);
    TEXT_IO.PUT_LINE (S);
end;
--->%---

What would you expect to be the output of the program?

Scroll down for the answer...

















































Well, I would have expected the output to be

@@@@@6
@@@@@5

But it is:

@@@@56
@@@@@5

Which is correct according to the definition of overwrite, but nevertheless I 
find this extremely surprising.

Am I alone in this?

Or can anyone please the rational on defining the behaviour of overwrite as it is?

Markus

             reply	other threads:[~2014-11-12 10:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-12 10:49 Markus Schöpflin [this message]
2014-11-12 12:55 ` Surprising behaviour of strings.fixed.overwrite G.B.
2014-11-12 15:49 ` Adam Beneschan
2014-11-12 23:19 ` Randy Brukardt
2014-11-13  8:15   ` Markus Schöpflin
2014-11-13 12:40     ` Simon Wright
2014-11-13 12:56       ` Markus Schöpflin
replies disabled

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