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

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.

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

Postby zcohen » Tue Jun 12, 2012 9:18 am

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
zcohen
 
Posts: 6
Joined: Wed Jun 06, 2012 12:41 am

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

Postby gugamilare » Tue Jun 12, 2012 5:07 pm

Try using the function append ;)
gugamilare
 
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil


Return to Homework

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron