I'm pretty new to Lisp and I have the following problem.
I'm trying to swap the numbers around in multiple lists and produce a list of lists as the result, so that all the numbers that were the 1st number in each list will all be collected in a list which is the 1st element of the result list; and all the numbers that were 2nd in each list will be collected in another list which is the 2nd element of the result list; and so on.
Here is an example:
(foo '((3 4 2 4) (2 5 6 9) (1 -2 8 10)) )
=> ((3 2 1) (4 5 -2) (2 6 8) (4 9 10))
My current solution is this:
(defun foo (list)
(mapcar #'list (values-list list))
)
As far as I understand it, values-list
should return all sublists from inside the given parameter list
. Then mapcar
will go through each element of each sublist and make them into a list.
This second part works, however what happens is that only the first sublist is used, resulting in ((3) (4) (2) (4))
instead of ((3 2 1) (4 5 -2) (2 6 8) (4 9 10))
.
Why is this?
(I'm using CLISP).