From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c3a7c1845ec5caf9 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Equality operator overloading in ADA 83 Date: 1997/04/27 Message-ID: X-Deja-AN: 237668889 References: <01bc4e9b$ac0e7fa0$72041dc2@lightning> <335CAEFE.35DC@elca-matrix.ch> <335E0A26.16D0@elca-matrix.ch> <33692089.5794807@news.airmail.net> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-04-27T00:00:00+00:00 List-Id: In article , dewar@merv.cs.nyu.edu (Robert Dewar) wrote: >< >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 := ; 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'(); begin or declare O : T is ; 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 ; 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 (818) 985-1271