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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,366b213c4abb1039 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!noris.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: What makes a procedure call 'dispatching' in Ada? Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <4b06a048$0$26319$4f793bc4@news.tdc.fi> <1ced67sbv38ke.1973smwq7n0uw.dlg@40tude.net> <4b06af42$0$6292$4f793bc4@news.tdc.fi> <1qmblkmu03nzr$.1sobppq4k2gm0$.dlg@40tude.net> <4b06f7bd$0$6275$4f793bc4@news.tdc.fi> Date: Fri, 20 Nov 2009 21:59:37 +0100 Message-ID: NNTP-Posting-Date: 20 Nov 2009 21:59:38 CET NNTP-Posting-Host: 915f9e5d.newsspool4.arcor-online.net X-Trace: DXC=0Fa=jmFE@4^aoembcbF;DQ4IUK On Fri, 20 Nov 2009 22:09:58 +0200, Niklas Holsti wrote: > Dmitry A. Kazakov wrote: >> On Fri, 20 Nov 2009 17:00:44 +0200, Niklas Holsti wrote: >> >>> A better analogy is code like this: >>> >>> procedure John (X : Integer ..) is >>> begin >>> ... >>> if X /= 1 then ... >>> end if; >>> ... >>> end Jonh; >>> >>> procedure Mary (...) is >>> begin >>> if X = 1 then >>> John (X); >>> else ... >>> end if; >>> end Mary; >> >> This is a wrong analogy. In your example John serves all values of X. > > You are not seeing the analogy that I intended. John does different > things for certain values of X, similar to a primitive operation that is > overridden for certain types (values of X when X is a tag). A primitive operation as a whole - yes, but a concrete overriding - no. In Ada these two operations are semantically and also by types different. A primitive operation is defined on T'Class, an overriding is defined on some S derived from T. So if you want an analogy it goes as follows: integers <---> T'Class 1 <---> S (derived from T) >> So when you call it with the value 1 it is not like dispatch, which >> chooses a body for just one tag. > > The test "if X /= 1" in John is analogous to one dispatch, Actually it does not, because {X | X /=1} is a subset of integers. Dispatch selects *one* member, not even a singleton subset, just a member. > and the test > "if X = 1" in Mary to another (perhaps it would have been clearer if the > latter had been "if X > 2", or some other pair of less correlated > checks). {X | X > 2} also denotes a subset. > My point is that it is quite normal and valid to make several > tests of the same value, as long as the tests are not redundant. Only, if each of these consequent tests would narrow the primary set of alternatives, not when these tests just repeating what was already determined. Dispatching narrows the set to one element in single step, there is nothing to narrow afterwards. BTW, I would favor a model where there would also be possible to narrow to a subset, e.g. from T'Class to S'Class, or even from (S1..S2)'Class. This would support consequent sub-dispatches, but still no re-dispatch. >>> Yes, there is a double check of X, but no, it is not a redundant check. >> >> But with dispatch the check is redundant. > > Obviously it is not, because the program behaves quite differently with > redispatching than without it. We are talking about program semantics. Your argument is like saying that the loop for I in 1..10**6 loop declare S : String (1..I); begin null; end; end loop; changes the program behavior (it might crash with Storage_Error). Yes it does, but that behavior change likely is not desired. Semantically the choice is made, so the behavior shall correspond to the choice as specified by the type. If the behavior does not correspond it, that is a bug. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de