Subject: Re: [SWIPL] how sort works?

From: Jan Wielemaker <[email-masked]>
Date: Wed, 26 Sep 2001 14:11:47 +0200

On Thu, 30 Aug 2001, Kobi wrote:
>
>Does somebody know how the function 'sort' works?
>from some reason whn I do listing(sort).
>It doesn't give me the way this function build.
>
>I know it should be something like
>
>insert_sort(List,Sorted):-i_sort(List,[],Sorted).
>i_sort([],Acc,Acc).
>i_sort([H|T],Acc,Sorted):-insert(H,Acc,NAcc),i_sort(T,NAcc,Sorted).
>   
>insert(X,[Y|T],[Y|NT]):-X>Y,insert(X,T,NT).
>insert(X,[Y|T],[X,Y|T]:-X=<Y.
>insert(X,[],[X]).
>But this is for numbers. anyway it doesn't what I need
>I have to see how sort is.

Sort and sorting is explained in many Prolog textbooks.  The
SWI-Prolog native implementation is written in C, based on
the observation that it is a very time-critical feature
of quite some applications and it can be done a little bit
more efficient from C. Hence the listing:

1 ?- listing(sort).

%   Foreign: sort/2

	--- Jan