Re: [eclipse-users] Question about setof/3 (and about _at_/1)

From: J. Manuel Velasco <jvelasco_at_...4...>
Date: Fri, 27 Oct 2006 13:27:39 +0200
Hello, 

I reply this mail just because when I send to the list I receice a reponse 
from bounces. So it's a test.

El Viernes, 27 de Octubre de 2006 02:29, Joachim Schimpf escribió:
> Ulrich Scholz wrote:
> > Hi everybody,
> >
> > a question about setof/3: The manual states that the result is sorted but
> > I could not find according to which ordering.  I guess, it's the standart
> > term order.
>
> Correct, the standard term order, as described in
> http://www.eclipse-clp.org/doc/bips/kernel/termcomp/compare-3.html
>
> > How could an implementation of setof/3 look like that uses an arbitrary,
> > i.e., user-supplied ordering?
>
> Use bagof/3 (or the faster findall/3), and sort the resulting list
> afterwards.
>
> Alternatively, you could take advantage of the fact that the standard order
> sorts on the leftmost argument of compound terms first.  So if you
> construct your result terms such that the leftmost argument is your sorting
> key, then the result list will automatically be ordered correctly:
>
> % sorted alphabetically
> ?- setof(X, member(X,[bb,c,aaa]), L).
> X = X
> L = [aaa, bb, c]
> Yes (0.00s cpu)
>
> % sorted by length first
> ?- setof(N-X, (member(X,[bb,c,aaa]),atom_length(X,N)), L).
> N = N
> X = X
> L = [1 - c, 2 - bb, 3 - aaa]
> Yes (0.00s cpu)
>
> > Thank you,
> >
> > Ulrich
> >
> >
> > BTW, the manual states "This predicate is sensitive to its module context
> > (tool predicate, see _at_/1)".  I guess, that sould read "... see @/2)".
>
> Quite right, thanks for spotting this!
>
>
> -- Joachim
>
> _______________________________________________
> ECLiPSe-Users mailing list
> ECLiPSe-Users_at_...2...
> http://www.crosscoreop.com/mailman/listinfo/eclipse-users
Received on Fri Oct 27 2006 - 12:27:41 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST