Alex
Alex

Reputation: 9740

LISP: Order items of a list in ascending order

I have a list L composed from random numbers

(defvar L '(1 4 2 6 4 3 4 1 9 5))

How to order it in ascending order?

list in ascending order is: L(1 1 2 3 4 4 4 5 6 9)

Upvotes: 1

Views: 2330

Answers (1)

Fred Foo
Fred Foo

Reputation: 363828

(sort L #'<)

or

(sort (copy-list L) #'<)

if you don't want to modify L in-place. If you want to use L afterward to get to the sorted list, rebind it:

(setf L (sort L #'<))

Upvotes: 5

Related Questions