From jan@swi.psy.uva.nl Wed Sep 26 14:15:05 2001
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f8QCF5v15268;
	Wed, 26 Sep 2001 14:15:05 +0200 (MET DST)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) id f8QCEsZ18082;
	Wed, 26 Sep 2001 14:14:54 +0200
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: "Kobi" <goldkobi@barak-online.net>, <prolog@swi.psy.uva.nl>
Subject: Re: [SWIPL] how sort works?
Date: Wed, 26 Sep 2001 14:11:47 +0200
X-Mailer: KMail [version 1.0.29.2]
Content-Type: text/plain
References: <001501c130ea$54dc78a0$507796d4@kobigold>
In-Reply-To: <001501c130ea$54dc78a0$507796d4@kobigold>
MIME-Version: 1.0
Message-Id: <0109261414530F.15353@gollem>
Content-Transfer-Encoding: 8bit

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

