This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

ascending

2 posts · 857 views

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)

Re: ascending

I know he didn't post any code, but I wanted practice so I wrote it anyway.
(defun my-reverse (list)
  (let ((x nil))
    (loop for i in list do
          (push i x)
          finally (return x))))
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.