2. Write a function called reverse, of one argument which
is a list, which returns the items in the list in reverse order,
For example,
(reverse '(a b d))
should return: (d b a)
ascending
-
- Posts: 59
- Joined: Sun May 29, 2011 8:52 pm
- Location: NY
- Contact:
Re: ascending
I know he didn't post any code, but I wanted practice so I wrote it anyway.
Note: To be a true reverse function it will need to work with strings, "hello", and vectors/arrays, #(1 2 3 4); mine does not. You can try to figure that out on your own.
Code: Select all
(defun my-reverse (list)
(let ((x nil))
(loop for i in list do
(push i x)
finally (return x))))
Code: Select all
COMMON-LISP-USER>
(my-reverse '(a b d))
(D B A)
Note: To be a true reverse function it will need to work with strings, "hello", and vectors/arrays, #(1 2 3 4); mine does not. You can try to figure that out on your own.