Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idiomatic Lisp way to create a list of sorted random numbers?

I'd like to find out what is the commonly accepted way to create a sorted list of random numbers in Common Lisp. In Clojure it is quite straightforward:

(sort (take 10 (repeatedly #(rand 10))))

I've found that in CL the following works:

(sort (loop for n below 10 collect (random 10)) #'<)

but does not read as well. Is there a cleaner way to express the same thing?

like image 552
Ana Avatar asked Jan 08 '23 10:01

Ana


1 Answers

Almost:

(sort (loop repeat 10 collect (random 10)) #'<)
like image 94
sds Avatar answered Jan 19 '23 07:01

sds