# [Openmcl-devel] sort lists

Paul Krueger plkrueger at comcast.net
Sat May 14 07:45:23 PDT 2011

```This looks suspiciously like a homework assignment, so let me just point out some reasons why your simple:
(stable-sort list #'< :key #'car)
couldn't produce the sort of result you're looking for. Using #'car as the key, you are restricting the sort to only consider the first element of each sublist even though the order that you desire clearly depends on considering perhaps many elements of each sublist. Similarly, the sort predicate #'< simply compares two numbers and your order depends on comparing two lists of numbers.

See if you can define a predicate that compares two lists of numbers such that for any two possible lists of numbers it returns true if the arguments are in the order that you desire and false otherwise (hint: think about doing that with a recursive function) and then use that rather than #'<.

Paul

On May 14, 2011, at 4:14 AM, Janusz Podrazik wrote:

> I try to sort lists but can't find any help to do deeper sort.
>
> example:
>
> (setq list '((0) (1) (2) (0 1 5) (0 1 3) (0 1 5) (0 3 0) (0) (1) (2 7 19) (0 0 3 0)))
>
> (stable-sort list #'< :key #'car)
> --> ((0) (0 1 5) (0 1 3) (0 1 5) (0 3 0) (0) (0 0 3 0) (1) (1) (2) (2 7 19))
>
> but I am looking for:
> --> ((0) (0) (0 0 3 0) (0 1 3) (0 1 5) (0 1 5) (0 3 0) (1) (1) (2) (2 7 19))
>
> --
> Janusz Podrazik
> MRAC Publishing
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

```