comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Equality operator overloading in ADA 83
Date: 1997/04/27
Date: 1997-04-27T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023680002704970206040001@news.ni.net> (raw)
In-Reply-To: dewar.862105379@merv


In article <dewar.862105379@merv>, dewar@merv.cs.nyu.edu (Robert Dewar) wrote:

><<Programmers innocently tried to do this:
>
>declare
>    S : String := F (...);
>begin
>
>Incredibly, that's illegal in Ada 83.  All that was required, though, was a
>simple repair:>>
>
>
>As usual, if you think something is incredible, it is probably because you
>did not carefully study the arguments on both sides.
>
>The reason that the above construct is illegal in Ada 83 is that it is
>potentially confusing, since once you are allowed to make such a declaration
>to a *variable* as opposed to a *constant*, then it sure looks as though
>you should be able to assign new string values to S, which is correct,
>and, in a *very* small step, it sure looks to people like you should be able
>to assign a different sized string.

But people need to be taught that there are
o  static strings - whose length is fixed, and determined statically (eg Pascal)
o dynamic strings - the length of string objects are fixed, but are
determined dynamically (eg Ada)
o flexible strings - the length of string objects can change (Algol 68)

So let's just tell new Ada programmers that Ada has dynamic strings.  I
find that it helps to think of the analogy between discriminated records
and strings, ie the constraint is determined by the initial value.

>As to your comments about Ada programmers not understanding runtime
>computed constants, surely not? Well I guess people can have all kinds
>of misinformation, but it is a critical feature of Ada that you can
>declare such constants, and indeed a criticism of much Ada code that I
>see is that it unnecessarily uses variables, where constants would be
>preferable.

I have had a similar experience.  I always have to remind programmers to
declare constants instead of variables.

I've been studying programming language theory of late, and have been
learning about functional programming, and the difference between binding
and assignment.

Interestingly - perhaps you can shed some light on the history - Ada
chooses assignment when binding would seem to do.  For example:

declare
   O : constant T := <T expression>;
begin

This declares a constant object, using assignment.  But why?  Couldn't one
bind O to a value, w/o using assignment, similar to a LISP let expression? 
Something like:

declare
   O : constant T'(<T expression>);
begin

or

declare
   O : T is <T expression>;
begin

The binding operator in Ada is "is" (I'm on very thin ice here).  For
example, I statically bind an identifier to a subprogram value:

function F return T is <function body expression>;

Now the reason this is interesting to me, is that it means I could give
limited objects a value during their elaboration, without breaking any rule
that says assigment isn't available for limited types.  I just seems to me
that object declaration should _bind_ a value to an object; it shouldn't
have anything to do with _assignment_, which I interpret to mean "move a
value into a certain memory cell."  That whole von Neumann thing.

The repercussion of the Ada design is that limited types must be definate,
and that the programmer can't choose the initial value for his limited
object (during its elaboration).

Here's an example of something I wanted to, but couldn't, because of this
problem, um, I mean "issue."  Without using heap, I want a data structure
to export a factory method that returns an iterator appropriate for
iterating over that data structure.

The iterator needs to be limited, because I'd like to have an access
discriminant that designates the data structure.  Sort of like:

type Root_Stack is abstract tagged private;

type Root_Stack_Iterator (Stack : access Root_Stack'Class) is
   abstract tagged limited private;

function Iterator (Stack : Root_Stack)
   return Root_Stack_Iterator'Class;

procedure Proc (Stack : in out Root_Stack'Class) is

   The_Iterator : Stack_Iterator'Class (Stack'Access) := 
      Iterator (Stack);   -- not legal Ada
begin

or something like that.  The idea is to have a class-wide object on the
stack, and for that class-wide object to be limited.  But I can't do that,
because I need to give the class-wide object a default value (because it's
indefinate), but can't because assignment isn't available.

Right now, the factory method must return a pointer to an iterator on the heap:

function New_Iterator (Stack : access Root_Stack)
   return Stack_Iterator_Access;

declare
   The_Stack : aliased Bounded_Stack;
   The_Iterator : Stack_Iterator_Access :=
      New_Iterator (The_Stack'Access);
begin

Why should there be any difference between an unconstrained object (a
class-wide iterator) on the stack or on the heap?  Yet I can do one, and
not the other.  

There's something a bit odd about "initialization during elaboration"
meaning the same thing as "assignment," but I'm not learned enough yet to
be able to say why.  Perhaps someone out there in cyberland can explain it
to me.

Oh, well, I'm just thinking out load.  I really like Ada, you know.

Matt

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




  reply	other threads:[~1997-04-27  0:00 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-21  0:00 Equality operator overloading in ADA 83 Manuel Wenger
1997-04-22  0:00 ` Matthew Heaney
1997-04-22  0:00   ` Philip Brashear
1997-04-22  0:00   ` Mats Weber
1997-04-22  0:00     ` Robert A Duff
1997-04-22  0:00       ` Mats Weber
1997-04-22  0:00       ` Matthew Heaney
1997-04-23  0:00         ` Mats Weber
1997-04-23  0:00           ` Robert Dewar
1997-04-24  0:00             ` Robert A Duff
1997-04-29  0:00             ` Mats Weber
1997-05-01  0:00               ` Robert Dewar
1997-04-23  0:00           ` Robert A Duff
1997-04-24  0:00             ` Mats Weber
1997-04-24  0:00               ` Matthew Heaney
1997-04-25  0:00                 ` Robert Dewar
1997-04-25  0:00                   ` Matthew Heaney
1997-04-26  0:00                     ` Robert A Duff
1997-04-26  0:00                     ` Robert Dewar
1997-04-25  0:00                 ` Robert Dewar
1997-04-25  0:00                   ` Matthew Heaney
1997-04-26  0:00                     ` Robert Dewar
1997-04-26  0:00                   ` Fergus Henderson
1997-04-26  0:00                     ` Robert A Duff
1997-04-26  0:00                       ` Robert Dewar
1997-04-27  0:00                     ` Robert Dewar
1997-04-24  0:00               ` Robert A Duff
1997-04-24  0:00                 ` Robert Dewar
1997-04-25  0:00                   ` Robert A Duff
1997-04-26  0:00                     ` Nick Roberts
1997-04-26  0:00                       ` Robert Dewar
1997-04-26  0:00                         ` Matthew Heaney
1997-05-02  0:00                           ` Nick Roberts
1997-05-04  0:00                             ` Robert Dewar
1997-05-05  0:00                               ` Robert A Duff
1997-05-05  0:00                               ` Mats Weber
1997-05-05  0:00                                 ` Robert Dewar
1997-05-06  0:00                                   ` Matthew Heaney
1997-05-06  0:00                                     ` Robert Dewar
1997-05-07  0:00                                     ` Tucker Taft
1997-04-26  0:00                       ` Robert A Duff
1997-04-26  0:00                         ` Robert Dewar
1997-04-27  0:00                           ` Robert A Duff
1997-04-26  0:00                             ` Robert Dewar
1997-04-28  0:00                               ` Simon Wright
1997-04-29  0:00                                 ` Robert I. Eachus
1997-04-29  0:00                       ` Mats Weber
1997-05-01  0:00                         ` Robert Dewar
     [not found]                           ` <01bc571c$01f3ffc0$5de2b8cd@p5120.bda>
1997-05-03  0:00                             ` Robert Dewar
1997-04-27  0:00                     ` Robert Dewar
1997-04-27  0:00                       ` Fergus Henderson
1997-04-27  0:00                         ` Robert Dewar
1997-04-28  0:00                           ` Fergus Henderson
1997-04-28  0:00                             ` Robert Dewar
1997-04-25  0:00                 ` Kevin Cline
1997-04-25  0:00                   ` Robert A Duff
1997-04-25  0:00                   ` Mats Weber
1997-04-27  0:00                     ` Robert Dewar
1997-04-29  0:00                       ` Mats Weber
1997-04-25  0:00                   ` Mats Weber
1997-04-25  0:00                     ` Robert Dewar
1997-04-29  0:00                       ` Mats Weber
1997-05-01  0:00                         ` Robert Dewar
1997-04-25  0:00                 ` Mats Weber
1997-04-27  0:00                 ` Geert Bosch
1997-04-28  0:00               ` Robert Dewar
1997-04-29  0:00                 ` Mats Weber
1997-04-29  0:00                   ` Robert A Duff
1997-04-29  0:00                     ` Matthew Heaney
1997-05-02  0:00                       ` Tucker Taft
1997-05-02  0:00                         ` Robert Dewar
1997-05-02  0:00                           ` Robert A Duff
1997-05-03  0:00                             ` Robert Dewar
1997-05-01  0:00                   ` Robert Dewar
1997-04-29  0:00                 ` Matthew Heaney
1997-05-01  0:00                   ` Robert Dewar
1997-04-28  0:00               ` Robert Dewar
1997-04-24  0:00         ` Robert Dewar
1997-04-22  0:00     ` Matthew Heaney
1997-04-23  0:00       ` Mats Weber
1997-04-23  0:00         ` Robert A Duff
1997-04-25  0:00           ` Kevin Cline
1997-04-25  0:00             ` Robert A Duff
1997-04-25  0:00             ` Matthew Heaney
1997-04-25  0:00               ` Robert A Duff
1997-04-25  0:00                 ` Jon S Anthony
1997-04-27  0:00                   ` Robert Dewar
1997-04-28  0:00                   ` Robert I. Eachus
1997-04-29  0:00                     ` Jon S Anthony
1997-04-26  0:00               ` Robert Dewar
1997-04-27  0:00                 ` Matthew Heaney [this message]
1997-04-27  0:00                   ` Robert A Duff
1997-04-26  0:00             ` Robert Dewar
1997-04-26  0:00               ` Matthew Heaney
1997-04-24  0:00     ` Robert Dewar
1997-04-24  0:00       ` Robert A Duff
1997-04-25  0:00         ` Robert Dewar
1997-04-25  0:00           ` Matthew Heaney
1997-04-26  0:00             ` Robert Dewar
1997-04-26  0:00               ` Robert A Duff
1997-04-26  0:00                 ` Robert Dewar
1997-04-26  0:00                   ` Matthew Heaney
1997-04-27  0:00                   ` Robert A Duff
1997-04-26  0:00                 ` Robert Dewar
1997-04-26  0:00                   ` Matthew Heaney
1997-04-27  0:00                     ` Robert Dewar
1997-04-27  0:00                   ` Robert A Duff
1997-04-26  0:00                     ` Robert Dewar
1997-05-02  0:00                       ` Nick Roberts
1997-05-04  0:00                         ` Robert Dewar
1997-04-22  0:00 ` Kevin Cline
1997-04-22  0:00   ` Mark A Biggar
1997-04-24  0:00   ` Keith Thompson
1997-04-22  0:00 ` Mats Weber
replies disabled

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