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.

Function to "push" a list to the right or left

2 posts · 3282 views

Hi everybody,
I have to write a function that (push-left (L)) "pushes" a list to thr right or to the left.

For example:
(push-left '(1 2 3 4)) will give (2 3 4 1)
(push-right'(1 2 3 4)) will give (4 1 2 3)

The lecturer said we can't use functions 'last' or 'butlast'.
I tried to solve it with no success. Can you give me direction? Is there a way to solve it by recursion?

I thought to simply do this: (cons (rest L) (first L)), but it gives (rest L) as a list. Is there a way to "unlist" it?

Thanks,
Zevi

Re: Function to "push" a list to the right or left

Try using the function append ;)