comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Multiple dispatch
Date: Sat, 11 Jun 2011 15:57:34 +0200
Date: 2011-06-11T15:57:34+02:00	[thread overview]
Message-ID: <11peqoimzzkd9$.foyzy9udb4dt$.dlg@40tude.net> (raw)
In-Reply-To: op.vwwxxyekule2fv@douda-yannick

On Sat, 11 Jun 2011 15:19:00 +0200, Yannick Duchêne (Hibou57) wrote:

> Le Sat, 11 Jun 2011 13:52:05 +0200, Dmitry A. Kazakov  
> <mailbox@dmitry-kazakov.de> a écrit:
>> Yes, that looks like the usual pattern for protocols and similar stuff,
>> when objects do not depend on the container.
> What kind of dependencies do you have in mind ? Object existence depending  
> on the container ? Or object's properties depending on the container ?

Any dependencies (correlations). Imagine the dispatching table. It is a 2D
matrix for double dispatch. In full dispatch the table is irregular, i.e.
there is no preferred way to index this matrix either by columns or by
rows.

In special cases there can be similarities between rows or between columns,
in that case you dispatch across the most varying dimension leaving the
least variance to the secondary dispatch.

> Another approach, with a more concrete-like example (which is not the one  
> I am actually dealing with… I wont tell more, as I prefer to keep this  
> talk as much abstract as possible) : you have two types, one for a  
> character string and one for an array of numbers, and two containers. Say  
> one container is a file and the other is anything else you wish (could be  
> a serial communication wire plugged to some device, as an example). Let  
> say there are two way to serialize each type. For the string, there is a  
> C-like serialization, that is, all characters first, with a final Unicode  
> U+0000, and a Pascal-like serialization, with a length first and then the  
> all characters. Let say there is something similar with the array of  
> numbers : it could either be serialized with a kind of null terminator,  
> and the other way, starting with its length and then its numbers. Say each  
> of the two container expect one or the other serialization.
> 
> This case seems more ambiguous at first sight, at it could seems as much  
> easy and clean to dispatch on either the container or the object. Eh, but  
> only one container type know about what null terminators are and only one  
> know about what lengths are. Now let say none of the array of numbers or  
> the character strings, know about what null terminators are. With such a  
> case, wouldn't it be better to dispatch first on the container ? Is that  
> the kind of dependency you though about ?

Yes, that is full dispatch, which is not decomposable. Returning to the
example with the 2D matrix of dispatch D, when it was the representation:

   D (i, j) = a (i) * b (j)

you can decompose full dispatch into cascaded dispatch (first a(i), then
b(j)).

>> The opposite case is
>> represented by drivers, when objects are maintained by the driver, you
>> might first dispatch on the driver type and then on the type of its
>> objects.
> I tried to figure out this one, but couldn't. Could you tell about a tiny  
> and short example ?

Typically driver has a task processing I/O requests. Queueing the request
naturally goes to the driver, so you dispatch first on the driver object.
Once you dequeue the request, you dispatch on the object handled by the
driver, e.g. write analogue 24-bit output etc.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2011-06-11 13:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-11 10:13 Multiple dispatch Yannick Duchêne (Hibou57)
2011-06-11 11:52 ` Dmitry A. Kazakov
2011-06-11 13:19   ` Yannick Duchêne (Hibou57)
2011-06-11 13:57     ` Dmitry A. Kazakov [this message]
2011-06-11 18:42       ` Emmanuel Briot
2011-06-11 19:12         ` Dmitry A. Kazakov
2011-06-15 10:30       ` Natasha Kerensikova
2011-06-15 11:10         ` Yannick Duchêne (Hibou57)
2011-06-15 11:19           ` Yannick Duchêne (Hibou57)
2011-06-15 14:59         ` Georg Bauhaus
2011-06-15 15:18           ` Yannick Duchêne (Hibou57)
2011-06-15 16:21             ` Georg Bauhaus
2011-06-12  5:13 ` Randy Brukardt
replies disabled

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