When evaluating the following code in Emacs, I get (2 3) as the final value of x. I’d expect (1 2 3). What am I missing?
(setq x '(2 1 3))
(sort x '<)
x
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you read
sort‘s documentation, you will find that it returns the sorted list, and the input list is modified by side effects. It does not say that the argument list will contain the sorted result — It is just somehow modified by the sorting algorithm. Or, to put it shortly:sortis destructive.So, you’ll want to bind/assign
sort‘s return value: