9fans archive / 1996 / 07 / 62 / prev next
From: Alexandre E. Kopilovitch aek@vib...
Subject: limbo
Date: Tue, 23 Jul 96 18:34:28 +0400
howard@pla... (Howard Trickey) writes:
>> would it be possible to implement a qsort replacement in limbo ?
>
>It is possible, but the answer is so ugly that the real answer is "no".
>
>(The caller could pass in a channel, and then be willing to answer
>questions like "is element 5 greater than element 3" over the channel;
>the answer could be an array of element indices in their sort order. Channels
>of ascii can be a universal way around type checking.)
>
>So, for instance, there is a module for sorting directory entries (in various
>ways), but no general purpose sorting module.
This answer seems rather strange to me, I think that Limbo already has
sufficient features for implementing general sorting module.
General sorting module (let's call it Sort) needs two external functions:
one to compare elements of array (taking two integer indices and producing
integer -1/0/+1 result) and another - to exchange them (again, taking their
integer indices).
Indeed, the question is how to give Sort access to user-supplied Compare
and Exchange functions. It can be done as follows: the user must supply
*implementation* of module which has a fixed name, say, Sort_User and the
fixed declaration:
Sort_User module {
Sort_Compare: fn (first_index: int, second_index: int) : int;
Sort_Exchange: fn (first_index: int, second_index: int);
};
I see no obstacles for user-supplied implementation of Sort_User module
to access an array to be sorted.
Then, one of the arguments for the actual sorting functions of the Sort
module must be *path* from which these functions should *load* proper
Sort_User implementation. So, Sort module can call user-supplied Sort_Compare
and Sort_Exchange functions because:
1) the name of Sort_User module is fixed
2) the path to Sort_User module is known to the Sort when it is called
3) the declaration of Sort_User module is fixed and contains declarations of
functions Sort_Compare and Sort_Exchange.
Alexander Kopilovitch aek@vib...
Saint-Petersburg
Russia