« Return to Thread: Numerical sort, reverse sort, etc?

Re: Numerical sort, reverse sort, etc?

by Jan Wielemaker :: Rate this Message:

Reply to Author | View in Thread

On Wednesday 16 April 2008 16:06, Ulrich Neumerkel wrote:
> > I'm tempted to define sort/3 as sort(+List, -Ordered, +Options), where
> > options provides:
> >
> >         * compare(:Goal)
> >         Comparision predicate.  Default compare/3
>
> Most orders are implemented providing only some boolean comparison.

Is that true?  See qsort() from the C-library.

> Yours is definitely better in certain circumstances, as it allows to
> remove duplicates. But what about orders where you do not have =
> naturally?

Nobody says you must return '='. Paulo suggested something along these
lines (using >, >=, etc.). I somehow recall some sort implementations
get very upset if you tell them (A op B) is true AND (B op A) is true.

It is of course possible to have both using mutually exclusive option
arguments.

> >         * reverse(+Boolean)
> >         Iff =true=, sort largest first
>
> Couldn't this be called ascending(Bool)? This sounds more natural to
> me.  And if you insist upon reverse, why not reversed?

You are right. ascending is better. Maybe even order(ascending) vs.
order(descending)?

> >         * duplicates(+Action)
> >         One of =keep= or =remove=
>
> Why not duplicates(true) meaning yes, there may be duplicates.

Hmmm.  I thought about that first, but thought keep/remove is clearer.
Nobody knows whether or not the result has duplicates if you do not
remove them.  I don't like 'may be' very much.

        Cheers --- Jan


------------
For further info, please visit http://www.swi-prolog.org/

To unsubscribe, send a plaintext mail with "unsubscribe prolog <e-mail>"
in its body to majordomo@...

 « Return to Thread: Numerical sort, reverse sort, etc?