So, to state the obvious:
(defun sortulists (L) (mapcar (lambda (uliste) (sort uliste (lambda (x1 x2) (or (symbolp x2) (and (numberp x1) (numberp x2) (< x1 x2)))))) L))
mapcar simply makes an anonymous function usage list for each element. To just focus on one element '(A 9 bh 2) , you can do:
;; same as the anonymous lambda, but named so we can test it a little (defun my< (x1 x2) (or (symbolp x2) (and (numberp x1) (numberp x2) (< x1 x2)))) (sort '(A 9 bh 2) #'my<) ; ==> (2 9 BHA) (my< 2 'a) ; ==> T (my< 2 3) ; ==> T (my< 3 3) ; ==> NIL (my< 'a 2) ; ==> NIL (my< 'a 'b) ; ==> T (my< 'b 'a) ; ==> T
Looking at my< x1 less than x2 if x2 is a character. x1 also smaller if both are numbers, and x1 is arithmetic less than x2 . For everything else, x1 is equal to or greater than x2 .
If you mix the characters in the argument list a bit, you can see that you get the characters in a different order than the original list. The reason is that the two characters being compared become t in both directions, so 'a less than 'b , and 'b less than 'a . The version in which we keep the character order as a result will look like this:
(stable-sort '(A 9 bh 2) (lambda (x1 x2) (and (numberp x1) (or (not (numberp x2)) (< x1 x2))))) ; ==> (2 9 ABH)
Note. I used the stable-sort function because sort not guaranteed to be stable. Stable means that equal objects are stored in the same order as the source.
source share