(defun my_shuffle (a b c d) (list b c d a))
The above code defines a function which will take 4 items and return a rearranged list of those 4 items. It can take input of 4 lists, 4 atoms, 4 numbers, 4 anything, but it cannot separate sublists present inside a single list.
What you can do is:
(defun my_shuffle (myList)
(list (second myList) (third myList) (fourth myList) (first myList)))
or
(defun my_shuffle (myList)
(list (cadr myList) (caddr myList) (cadddr myList) (car myList)))
or
(defun my_shuffle (myList)
(list (nth 1 myList) (nth 2 myList) (nth 3 myList) (nth 1 myList)))
car
returns the first element of a list
cdr
returns the tail of a list (part of the list following
car
of the list)
I have used combinations of car and cdr to extract the different elements of the list. Find that in your textbook.
first
, second
, third
, fourth
are relatively easy to use and do the same thing as car
, cadr
, caddr
and cadddr
(nth x list)
returns the (x+1)th item of the list, counting from zero.
So,
(nth 3 (list a b c d)) => d
(nth 0 (list a b c d)) => a
and so on.
(my_shuffle 1 2 3 4)
returns(2 3 4 1)
. How are you calling it? – Mesquite(my_shuffle (list 1 2 3 4))
. It seems I'm passing incorrect argument. As you say(my_shuffle 1 2 3 4)
returns(2 3 4 1)
and this is what I want. – Penthousemy_shuffle([1,2,3,4])
in Python doesn't work either. None of them takes one list parameter, but both takes 4 arguments and return a list with those in a different order than called. – Portraitist