·············@gmail.com (sharda mishra) writes:
>
> Hello every one
>
> PLEASE help me writing the following program in LISP language
> ;-
>
> Write a LISP function ODD-REVERSE which reverses the elements
> occuring at odd numbered position but keeps the elements at even
> numbered position in their given position.
Here's my entry:
(defun odd-reverse (list)
(let ((provisional-result
(mapcan #'list
(loop for x on list by #'cddr
collect (car x))
(nreverse (loop for x on (rest list) by #'cddr
collect (car x))))))
(if (oddp (length list))
(nconc provisional-result (last list))
provisional-result)))
(odd-reverse '(0 1 2 3 4 5 6 7)) => (0 7 2 5 4 3 6 1)
(odd-reverse '(0 1 2 3 4 5 6 7 8)) => (0 7 2 5 4 3 6 1 8)
--
Thomas A. Russ, USC/Information Sciences Institute