From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Tue, 23 Jul 1996 18:34:28 +0400 From: Alexandre E. Kopilovitch aek@vib.usr.pu.ru Subject: limbo Topicbox-Message-UUID: 49590b18-eac8-11e9-9e20-41e7f4b1d025 Message-ID: <19960723143428.Vp1Rr7eYwDUbgHPgtS7nIZTYZyWd86TIvrTEWgrbWmo@z> howard@plan9.BEll-labs.COM (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.usr.pu.ru Saint-Petersburg Russia