Discussion of Common Lisp


Postby murali » Fri Jul 01, 2011 10:35 am

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)
Posts: 15
Joined: Fri Jul 01, 2011 10:11 am

Re: ascending

Postby I X Code X 1 » Fri Jul 01, 2011 12:06 pm

I know he didn't post any code, but I wanted practice so I wrote it anyway.

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
(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.
User avatar
I X Code X 1
Posts: 59
Joined: Sun May 29, 2011 8:52 pm
Location: NY

Return to Common Lisp

Who is online

Users browsing this forum: Bing [Bot] and 1 guest