comp.lang.ada
 help / color / mirror / Atom feed
* Re: Expectation of Access Value Equality
  2003-09-05 13:35 Expectation of Access Value Equality Nick Roberts
@ 2003-09-05 13:02 ` chris
  2003-09-05 17:56   ` Nick Roberts
  2003-09-05 19:10 ` Robert I. Eachus
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 14+ messages in thread
From: chris @ 2003-09-05 13:02 UTC (permalink / raw)


Nick Roberts wrote:


> (c) What would you think of an implementation that caused this behaviour?
> (What would you think of an implementation that printed four lines in both
> cases?)

It wouldn't be obeying the typing rules of the language.  Perhaps you 
meant A_String_Array to accesses to A_String?  If so,

(a) I would expect 4 lines
(b) ditto
(c) it'd be working correctly iiu the languages rules correctly.

> (d) I'd be grateful for a very brief indication of your level and broad
> area(s) of programming experience, in Ada and other languages.

Familiar: Ada, Java, Pascal

Ok: C, SQL

Dabbled In: C++, Erlang, Haskell

I'm a student with 0 years industry service behind me so I don't use Ada 
everyday, if that's relevant.


Chris




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

* Expectation of Access Value Equality
@ 2003-09-05 13:35 Nick Roberts
  2003-09-05 13:02 ` chris
                   ` (9 more replies)
  0 siblings, 10 replies; 14+ messages in thread
From: Nick Roberts @ 2003-09-05 13:35 UTC (permalink / raw)


I'm asking for the help of Ada programmers of all levels of experience.

Given the following declarations:

   type A_String is access constant String;

   function "+" (S: String) return A_String is
   begin
      return new String'(S);
   end;

   type A_String_Array is array (Positive range <>) of String;

   procedure Print (A: in A_String_Array) is
      Sentinel: constant A_String := A(A'Last);
      Current: Positive := A'First;
   begin
      loop
         Put_Line( A(Current).all );
         exit when A(Current) = Sentinel;
         Current := Current + 1;
      end loop;
   end;

(a) Would you be surprised by:

   Print( (+"foo",+"bar",+"",+"") );

printing three lines?

(b) Would you be surprised by:

   Print( (+"foo",+"bar",+"hum",+"foo") );

printing one line?

(c) What would you think of an implementation that caused this behaviour?
(What would you think of an implementation that printed four lines in both
cases?)

(d) I'd be grateful for a very brief indication of your level and broad
area(s) of programming experience, in Ada and other languages.

I would be very grateful for as many people replying as possible, preferably
in this news group, but privately if you prefer. Thanks.

--
Nick Roberts
E-mail: nickroberts@blueyonder.co.uk
Jabber: debater@charente.de [ICQ: 159718630]






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

* Re: Expectation of Access Value Equality
  2003-09-05 13:02 ` chris
@ 2003-09-05 17:56   ` Nick Roberts
  0 siblings, 0 replies; 14+ messages in thread
From: Nick Roberts @ 2003-09-05 17:56 UTC (permalink / raw)


"chris" <spamoff.danx@ntlworld.com> wrote in message
news:yE06b.1987$Ve3.865@newsfep4-winn.server.ntli.net...

> > (c) What would you think of an implementation that caused this
behaviour?
> > (What would you think of an implementation that printed four lines in
both
> > cases?)
>
> It wouldn't be obeying the typing rules of the language.  Perhaps you
> meant A_String_Array to accesses to A_String?  If so,

I'm sorry, I did mean:

   type A_String_Array is array (Positive range <>) of A_String;

instead of:

   type A_String_Array is array (Positive range <>) of String;

> (a) I would expect 4 lines
> (b) ditto
> (c) it'd be working correctly iiu the languages rules correctly.
>
> > (d) I'd be grateful for a very brief indication of your level and broad
> > area(s) of programming experience, in Ada and other languages.
>
> Familiar: Ada, Java, Pascal
>
> Ok: C, SQL
>
> Dabbled In: C++, Erlang, Haskell
>
> I'm a student with 0 years industry service behind me so I don't use Ada
> everyday, if that's relevant.

Thank you Chris, it's relevant, and it's useful. Thanks!

--
Nick Roberts
Jabber: debater@charente.de [ICQ: 159718630]







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

* Re: Expectation of Access Value Equality
  2003-09-05 13:35 Expectation of Access Value Equality Nick Roberts
  2003-09-05 13:02 ` chris
@ 2003-09-05 19:10 ` Robert I. Eachus
  2003-09-05 19:32 ` Jeffrey Carter
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Robert I. Eachus @ 2003-09-05 19:10 UTC (permalink / raw)


Nick Roberts wrote:
> I'm asking for the help of Ada programmers of all levels of experience...

> (a) Would you be surprised by:
> 
>    Print( (+"foo",+"bar",+"",+"") );
> 
> printing three lines?
> 
> (b) Would you be surprised by:
> 
>    Print( (+"foo",+"bar",+"hum",+"foo") );
> 
> printing one line?
> 
> (c) What would you think of an implementation that caused this behaviour?

If the indicated correction to the program had been made, I would assume 
that the mode in which the compiler was used allowed subroutines to be 
treated as if pragma Pure (RM 10.2.1) had been applied to them.  (And 
that a compiler might have such a mode would not disturb me at all.)

> (What would you think of an implementation that printed four lines in both
> cases?)

I'd conclude that, in this area, it implemented the standard correctly.

> (d) I'd be grateful for a very brief indication of your level and broad
> area(s) of programming experience, in Ada and other languages.

Expert.

--
                                       Robert I. Eachus

"As far as I'm concerned, war always means failure." -- Jacques Chirac, 
President of France
"As far as France is concerned, you're right." -- Rush Limbaugh




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

* Re: Expectation of Access Value Equality
  2003-09-05 13:35 Expectation of Access Value Equality Nick Roberts
  2003-09-05 13:02 ` chris
  2003-09-05 19:10 ` Robert I. Eachus
@ 2003-09-05 19:32 ` Jeffrey Carter
  2003-09-05 19:35 ` Simon Wright
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Jeffrey Carter @ 2003-09-05 19:32 UTC (permalink / raw)


Nick Roberts wrote:

> I'm asking for the help of Ada programmers of all levels of experience.
> 
> Given the following declarations:
> 
>    type A_String is access constant String;
> 
>    function "+" (S: String) return A_String is
>    begin
>       return new String'(S);
>    end;
> 
>    type A_String_Array is array (Positive range <>) of String;

Later corrected this line with:

> I'm sorry, I did mean:
> 
>    type A_String_Array is array (Positive range <>) of A_String;
> 
>    procedure Print (A: in A_String_Array) is
>       Sentinel: constant A_String := A(A'Last);
>       Current: Positive := A'First;
>    begin
>       loop
>          Put_Line( A(Current).all );
>          exit when A(Current) = Sentinel;
>          Current := Current + 1;
>       end loop;
>    end;

My reaction is to wonder why you're not using a for loop here:

for Current in A'range loop

If you can come up with a real example where this is relevant, it would 
make the answers of greater interest.

At first glance, I'd expect both examples to print 4 lines. If an 
implementation didn't give that behavior, though, I suspect I'd look 
further at the fact that you're using "access constant", so the compiler 
could save only a single copy of the duplicated values, and use the same 
access value for equal strings. Both results (4 lines or fewer than 4 
lines) seem legal.

> (d) I'd be grateful for a very brief indication of your level and broad
> area(s) of programming experience, in Ada and other languages.

I've been using Ada since 1984; I'm not a language lawyer or compiler 
writer, but I think I have a pretty good understanding of the language. 
I've also used a number of other languages, including BASICs, Pascals, 
FORTRAN-66, COBOL, C, and assemblers.

-- 
Jeff Carter
"You couldn't catch clap in a brothel, silly English K...niggets."
Monty Python & the Holy Grail
19




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

* Re: Expectation of Access Value Equality
  2003-09-05 13:35 Expectation of Access Value Equality Nick Roberts
                   ` (2 preceding siblings ...)
  2003-09-05 19:32 ` Jeffrey Carter
@ 2003-09-05 19:35 ` Simon Wright
  2003-09-06  0:25 ` Matthew Heaney
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Simon Wright @ 2003-09-05 19:35 UTC (permalink / raw)


"Nick Roberts" <nickroberts@blueyonder.co.uk> writes:

> I'm asking for the help of Ada programmers of all levels of experience.
> 
> Given the following declarations:
> 
>    type A_String is access constant String;
> 
>    function "+" (S: String) return A_String is
>    begin
>       return new String'(S);
>    end;
> 
>    type A_String_Array is array (Positive range <>) of String;
> 
>    procedure Print (A: in A_String_Array) is
>       Sentinel: constant A_String := A(A'Last);
>       Current: Positive := A'First;
>    begin
>       loop
>          Put_Line( A(Current).all );
>          exit when A(Current) = Sentinel;
>          Current := Current + 1;
>       end loop;
>    end;

That is a pretty bizarre piece of code! (E&OE). I guess there might be
circumstances in which the part at issue was the right thing to do ..

> (a) Would you be surprised by:
> 
>    Print( (+"foo",+"bar",+"",+"") );
>
> printing three lines?

yes

> (b) Would you be surprised by:
> 
>    Print( (+"foo",+"bar",+"hum",+"foo") );
> 
> printing one line?

yes

> (c) What would you think of an implementation that caused this behaviour?
> (What would you think of an implementation that printed four lines in both
> cases?)

odd, needs study
(ok)

> (d) I'd be grateful for a very brief indication of your level and broad
> area(s) of programming experience, in Ada and other languages.

expert user, not language lawyer
would be surprised by the same behaviours in C
otherwise tend to use scripting languages so question doesn't arise


If an amended ARM said the surprising behaviours were OK I would not
be concerned, plenty of other implementation-defined stuff to avoid in
the language!



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

* Re: Expectation of Access Value Equality
  2003-09-05 13:35 Expectation of Access Value Equality Nick Roberts
                   ` (3 preceding siblings ...)
  2003-09-05 19:35 ` Simon Wright
@ 2003-09-06  0:25 ` Matthew Heaney
  2003-09-06  2:41 ` Steve
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Matthew Heaney @ 2003-09-06  0:25 UTC (permalink / raw)


"Nick Roberts" <nickroberts@blueyonder.co.uk> writes:

> (a) Would you be surprised by:
> 
>    Print( (+"foo",+"bar",+"",+"") );
>
> printing three lines?

No.  That's what I expected it to print.


> (b) Would you be surprised by:
> 
>    Print( (+"foo",+"bar",+"hum",+"foo") );
> 
> printing one line?

No.  That's what I expected it to print.

 
> (c) What would you think of an implementation that caused this behaviour?
> (What would you think of an implementation that printed four lines in both
> cases?)

I think your program is broken, not any compiler implementation.  The
problem is that you have items identical to your sentinel.

 
> (d) I'd be grateful for a very brief indication of your level and broad
> area(s) of programming experience, in Ada and other languages.

I have been programming in Ada for over 15 years.  I am fluent in Ada95 and C++.

 



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

* Re: Expectation of Access Value Equality
  2003-09-05 13:35 Expectation of Access Value Equality Nick Roberts
                   ` (4 preceding siblings ...)
  2003-09-06  0:25 ` Matthew Heaney
@ 2003-09-06  2:41 ` Steve
  2003-09-06 22:01 ` Georg Bauhaus
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Steve @ 2003-09-06  2:41 UTC (permalink / raw)


"Nick Roberts" <nickroberts@blueyonder.co.uk> wrote in message
news:bja3fi$glkjh$1@ID-25716.news.uni-berlin.de...
[snip]
> (a) Would you be surprised by:
>
>    Print( (+"foo",+"bar",+"",+"") );
>
> printing three lines?

No.

> (b) Would you be surprised by:
>
>    Print( (+"foo",+"bar",+"hum",+"foo") );
>
> printing one line?

No.

> (c) What would you think of an implementation that caused this behaviour?
> (What would you think of an implementation that printed four lines in both
> cases?)

I would think that an implementation taking advantage of common strings
might have produce a smaller footprint by default.  This example gives me
more of an opinion of the quality of the source code (ambiguous) than the
quality of the compiler.  It looks more like the "C" way of doing things
than the Ada way.

> (d) I'd be grateful for a very brief indication of your level and broad
> area(s) of programming experience, in Ada and other languages.

Programmed various systems used in industrial automation.  Some hard, some
soft real-time.

Languages:
  Ada 95, Pascal (EPascal, Turbo Pascal, Delphi), C, FORTH
  HP-1000 Assembly, C++, FORTRAN

Prefer:
  Ada 95

Operating Systems:
  PDOS, VersaDOS, VaxELN, VxWorks, Windows NT

(BTW: I only listed systems I have actually USED, I have tinkered with
Modula2, Linux, RTEMS ).

Steve
(The Duck)

> I would be very grateful for as many people replying as possible,
preferably
> in this news group, but privately if you prefer. Thanks.
>
> --
> Nick Roberts
> E-mail: nickroberts@blueyonder.co.uk
> Jabber: debater@charente.de [ICQ: 159718630]
>
>
>





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

* Re: Expectation of Access Value Equality
  2003-09-05 13:35 Expectation of Access Value Equality Nick Roberts
                   ` (5 preceding siblings ...)
  2003-09-06  2:41 ` Steve
@ 2003-09-06 22:01 ` Georg Bauhaus
  2003-09-08  9:08 ` Preben Randhol
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Georg Bauhaus @ 2003-09-06 22:01 UTC (permalink / raw)


Nick Roberts <nickroberts@blueyonder.co.uk> wrote:
: (a) Would you be surprised by:
: 
:   Print( (+"foo",+"bar",+"",+"") );
: 
: printing three lines?

No.

 
: (b) Would you be surprised by:
: 
:   Print( (+"foo",+"bar",+"hum",+"foo") );
: 
: printing one line?

No, but I was surprised to see four lines (which adds 
TODO items to my list, among them, look up the meaning of new
with string literals. Is a pointer to a new string made from
a literal different from another of the same making?)

: (c) What would you think of an implementation that caused this behaviour?
: (What would you think of an implementation that printed four lines in both
: cases?)

I'd think that it might be correct and that I am wrong.
But I'd try to make sure I am wrong.

: (d) I'd be grateful for a very brief indication of your level and broad
: area(s) of programming experience, in Ada and other languages.

Writing programs for a living mostly in Java (standalone and for Servlet
containers), XSL, Perl; some teaching experience; Ada hobbyist.


Georg



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

* Re: Expectation of Access Value Equality
  2003-09-05 13:35 Expectation of Access Value Equality Nick Roberts
                   ` (6 preceding siblings ...)
  2003-09-06 22:01 ` Georg Bauhaus
@ 2003-09-08  9:08 ` Preben Randhol
  2003-09-08  9:09   ` Andy
  2003-09-10 18:39 ` Mário Amado Alves
  2003-09-23 10:46 ` Jacob Sparre Andersen
  9 siblings, 1 reply; 14+ messages in thread
From: Preben Randhol @ 2003-09-08  9:08 UTC (permalink / raw)


Nick Roberts wrote:
> (a) Would you be surprised by:
> 
>    Print( (+"foo",+"bar",+"",+"") );
> 
> printing three lines?
> 
> (b) Would you be surprised by:
> 
>    Print( (+"foo",+"bar",+"hum",+"foo") );
> 
> printing one line?
>
> 
> (c) What would you think of an implementation that caused this behaviour?
> (What would you think of an implementation that printed four lines in both
> cases?)

I don't know I. Running your program produces 4 lines in both cases.

Compiler: Gnat 3.15p on Debian GNU/Linux

Preben
-- 
�I think fish is nice, but then I think that rain is wet.
 So who am I to judge.�
                 - The Hitch Hiker's Guide to the Galaxy (radioplay)



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

* Re: Expectation of Access Value Equality
  2003-09-08  9:08 ` Preben Randhol
@ 2003-09-08  9:09   ` Andy
  2003-09-09 22:31     ` Nick Roberts
  0 siblings, 1 reply; 14+ messages in thread
From: Andy @ 2003-09-08  9:09 UTC (permalink / raw)


Preben Randhol wrote:
> 
> Nick Roberts wrote:
> > (a) Would you be surprised by:
> >
> >    Print( (+"foo",+"bar",+"",+"") );
> >
> > printing three lines?
Yes

> >
> > (b) Would you be surprised by:
> >
> >    Print( (+"foo",+"bar",+"hum",+"foo") );
> >
> > printing one line?
Yes

> >
> > (c) What would you think of an implementation that caused this behaviour?
Crap!

> > (What would you think of an implementation that printed four lines in both
> > cases?)
Potentially not crap.
 
> I don't know I. Running your program produces 4 lines in both cases.
Ditto

> Compiler: Gnat 3.15p on Debian GNU/Linux
Compiler:  antique Gnat 3.11p on an even older Windoze 95
 
> Preben

Regards,
Andy



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

* Re: Expectation of Access Value Equality
  2003-09-08  9:09   ` Andy
@ 2003-09-09 22:31     ` Nick Roberts
  0 siblings, 0 replies; 14+ messages in thread
From: Nick Roberts @ 2003-09-09 22:31 UTC (permalink / raw)


Thanks to everyone replying.

--
Nick Roberts
Jabber: debater@charente.de [ICQ: 159718630]






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

* Re: Expectation of Access Value Equality
  2003-09-05 13:35 Expectation of Access Value Equality Nick Roberts
                   ` (7 preceding siblings ...)
  2003-09-08  9:08 ` Preben Randhol
@ 2003-09-10 18:39 ` Mário Amado Alves
  2003-09-23 10:46 ` Jacob Sparre Andersen
  9 siblings, 0 replies; 14+ messages in thread
From: Mário Amado Alves @ 2003-09-10 18:39 UTC (permalink / raw)


"Nick Roberts" <nickroberts@blueyonder.co.uk> wrote in message news:<bja3fi$glkjh$1@ID-25716.news.uni-berlin.de>...
> I'm asking for the help of Ada programmers of all levels of experience.
> 
> Given the following declarations:
> 
>    type A_String is access constant String;
> 
>    function "+" (S: String) return A_String is
>    begin
>       return new String'(S);
>    end;
> 
>    type A_String_Array is array (Positive range <>) of A_String;
> 
>    procedure Print (A: in A_String_Array) is
>       Sentinel: constant A_String := A (A'Last);
>       Current: Positive := A'First;
>    begin
>       loop
>          Put_Line (A (Current).all);
>          exit when A (Current) = Sentinel;
>          Current := Current + 1;
>       end loop;
>    end;
> 
> (a) Would you be surprised by:
> 
>    Print( (+"foo",+"bar",+"",+"") );
>
> printing three lines?

Yes.
 
> (b) Would you be surprised by:
> 
>    Print( (+"foo",+"bar",+"hum",+"foo") );
> 
> printing one line?

Yes.

> (c) What would you think of an implementation that caused this behaviour?

I would think the behaviour was not in accordance with the deep,
natural meaning of "new". I would suspect the system was trying to
reuse memory, at the cost of some search time. And I would hope this
behaviour was a compiler option. And wish it was not the default.

> (What would you think of an implementation that printed four lines in both
> cases?)

All is well.

> (d) I'd be grateful for a very brief indication of your level and broad
> area(s) of programming experience, in Ada and other languages.

I'm programming since 1984, in Ada since 1997, and before it was in
BASIC, Assembler, Clipper, QuickBASIC, Pascal, C, C++, Java... I'm an
academic now but I have worked for industry and sometimes I still do
freelance work.



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

* Re: Expectation of Access Value Equality
  2003-09-05 13:35 Expectation of Access Value Equality Nick Roberts
                   ` (8 preceding siblings ...)
  2003-09-10 18:39 ` Mário Amado Alves
@ 2003-09-23 10:46 ` Jacob Sparre Andersen
  9 siblings, 0 replies; 14+ messages in thread
From: Jacob Sparre Andersen @ 2003-09-23 10:46 UTC (permalink / raw)


Nick Roberts wrote:

> (a) Would you be surprised by:
> 
>    Print( (+"foo",+"bar",+"",+"") );
> 
> printing three lines?

Not really.  But I don't think I would code like that, because I am
uncertain of the meaning and would have to look the gory details up in
the LRM.

> (b) Would you be surprised by:
> 
>    Print( (+"foo",+"bar",+"hum",+"foo") );
> 
> printing one line?

As above.

> (c) What would you think of an implementation that caused this behaviour?
> (What would you think of an implementation that printed four lines in both
> cases?)

That depends on what the LRM says on the subject.  (haven't checked it)

> (d) I'd be grateful for a very brief indication of your level and broad
> area(s) of programming experience, in Ada and other languages.

I have used Ada for my work since 1995.  Before that I used Borland
Pascal.  In addition to that I have programmed a bit in Fortran,
COMAL-80, BASIC (Sinclair, ABC and MS versions), C, C++, Erlang, OCaml
and a few other (mostly procedural) languages.

I am not a programmer by profession or education.

Jacob
-- 
Wie "Tippfehler !?" Mein Modem hat doch Fehlerkorrektur...




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

end of thread, other threads:[~2003-09-23 10:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-05 13:35 Expectation of Access Value Equality Nick Roberts
2003-09-05 13:02 ` chris
2003-09-05 17:56   ` Nick Roberts
2003-09-05 19:10 ` Robert I. Eachus
2003-09-05 19:32 ` Jeffrey Carter
2003-09-05 19:35 ` Simon Wright
2003-09-06  0:25 ` Matthew Heaney
2003-09-06  2:41 ` Steve
2003-09-06 22:01 ` Georg Bauhaus
2003-09-08  9:08 ` Preben Randhol
2003-09-08  9:09   ` Andy
2003-09-09 22:31     ` Nick Roberts
2003-09-10 18:39 ` Mário Amado Alves
2003-09-23 10:46 ` Jacob Sparre Andersen

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