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: 103376,50e705cdf2767cc6 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder.news-service.com!feeder.news-service.com!2a02:590:1:1::196.MISMATCH!news.teledata-fn.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Parser interface design 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: <1p6q05xtgjspf.7qanu7wlynvi$.dlg@40tude.net> Date: Thu, 7 Apr 2011 22:31:17 +0200 Message-ID: NNTP-Posting-Date: 07 Apr 2011 22:31:17 CEST NNTP-Posting-Host: a687772e.newsspool4.arcor-online.net X-Trace: DXC=`0hNeCWlZoC02Sh8E_NfIA4IUK On Thu, 7 Apr 2011 19:14:33 +0000 (UTC), Natasha Kerensikova wrote: > Hello, > > On 2011-04-06, Dmitry A. Kazakov wrote: >> On Wed, 6 Apr 2011 10:11:46 +0000 (UTC), Natasha Kerensikova wrote: >> >>> I thought the most idiomatic way of putting together a bunch of >>> callbacks in Ada would be to use an Interface, and then rely on dynamic >>> dispatch. >> >> It also can be an abstract base type with primitive operations defined >> null. The advantage is that you can have a "null function" and non-null >> implementations with a type, which you cannot with an interface. > > That's an interesting idea, however that prevents a renderer object from > being based on another type, like Controlled or Limited_Controlled - > unless I base the abstract type on them. > > The null function fact seems very interesting though. Is it possible to > test externally whether a given dispatched function is null? I meant "null" in the sense of an elementary implementation, e.g. function Get_Line (...) return String is begin raise End_Error; end String; With interfaces you can do: procedure Bar (...) is null; but cannot function Get_Line (...) return String is null; and furthermore you cannot provide any implementation for Get_Line. Interface is such a broken concept. > I'm asking > because in my C implementation, a NULL callback was a meant to > communicate to the parser that the associated active character should > no longer be considered active, thereby switching off that particular > feature (which is very different from having a no-op callback). Why should you test for anything? Just make the implementation do what is required to do in order to achieve the desired effect. >>> The approach using tagged types implementing an interface seems heavier. >> >> You should not try to pack everything onto one types hierarchy. The parser >> and renderer should likely be two different hierarchies glued together >> through a mix-in in a third object aggregating both implementation. > > Actually I don't understand why there would be a second or even a third > object in there. Would you mind expanding? Parser should not know anything about rendering. Likewise it should know nothing about the source. It is better to decouple such things into independent hierarchies. Objects instantiating each hierarchy can be aggregated or mixed-in by the user. > In the example I proposed, the only object was the parser, which is > tagged in order to provide dynamic dispatching. That's what would be in > the renderer package. The parser package would be only a procedure, to > which the client hand over the flow control, and which uses the > callbacks from the tagged instance provided by the client. I don't see > how to get from this to something where the parser and/or the client has > a tagged object. Parser is such an object encapsulating the parsing state. You certainly would like to have it reentrant, so you need to keep that state somewhere. The source object encapsulates the state of the source being parsed, e.g. a file keeps its current position. The renderer object holds the rendering context etc. An ability to keep hidden state is key advantage of an OO design over naked procedures tossed here and there. >>> So what would be the best approach to interface a parser and a renderer? >> >> The parsers I implemented used primitive operations as sematic callbacks. > > That sound exactly like what I proposed, doesn't it? Yes it does. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de