Search the web
Sign In
New User? Sign Up
bangalore-lisp · The Bangalore Common Lisp Study Group
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
About reverse function   Message List  
Reply | Forward Message #466 of 501 |
Re: [bangalore-lisp] About reverse function

Thanks a lot to all,
This mail-chain has produced at least three ways of doing the same thing and all of them are different and elegant.
Great going guys... let us start some thing interesting like a project developed by us. I really like to join some project which has GPL but would like to that with in our group. What do you suggest?
A fair warning from my side that I am a new lisper so learning a lot from you all.
 
Thanks to all again,
 
Samik
 
P.S. If any one of you have some time for my blog please visit it and post your suggestion there:
 
----- Original Message ----
From: pramod shinde <prmdshinde@...>
To: bangalore-lisp@yahoogroups.com
Sent: Tuesday, 18 September, 2007 9:22:41 AM
Subject: Re: [bangalore-lisp] About reverse function

Thanks samik,

i m able to do the reverse function:

(defun rev (x)
(if (endp x)
nil
(append (rev (cdr x)) (list (car x)))))
 > rev '(a b c a d)
(d a c b a)
 
Pramod K.Shinde


----- Original Message ----
From: samik chakraborty <samik_126@yahoo. co.in>
To: bangalore-lisp@ yahoogroups. com
Sent: Sunday, September 16, 2007 10:14:53 PM
Subject: Re: [bangalore-lisp] About reverse function

Hi Pramod,

 

Sorry to spell your name incorrect last time. The following code uses a recursive call to do a reverse of a list only problem is the tr variable it needs to be set to ‘() each time after a call to this reverse function. I must be missing something stupid here if you can rectify it, will be great.

 

CL-USER> (setf tr '())

 

CL-USER> (defun rev(lst)

               (setf tr (list* (car lst) tr))

               (if (not (eq (cdr lst) nil))

                   (rev (cdr lst))

                   (return-from rev tr)))

 

CL-USER> (rev (list 1 2 3 4 5))

(5 4 3 2 1)

 

 

As always, very best

 

Samik



----- Original Message ----
From: pramod shinde <prmdshinde@yahoo. com>
To: bangalore-lisp@ yahoogroups. com
Sent: Monday, 17 September, 2007 2:50:08 AM
Subject: [bangalore-lisp] About reverse function

Hi all ,
      Can anybody write the recursive function LISP function that will reverse elements of the list(please don't use built-in reverse function).?
       I have tried the answer with car,cdar,last, lastbut .But I am not able to come at exact answer.
 Thanks for your any suggestion.

Regards,
Pramod K.Shinde



Yahoo! oneSearch: Finally, mobile search that gives answers, not web links.



Did you know? You can CHAT without downloading messenger. Click here



Building a website is a piece of cake.
Yahoo! Small Business gives you all the tools to get online.



Try the revolutionary next-gen Yahoo! Mail. Click here.

Tue Sep 18, 2007 6:47 am

samik_126
Offline Offline
Send Email Send Email

Forward
Message #466 of 501 |
Expand Messages Author Sort by Date

Hi all , Can anybody write the recursive function LISP function that will reverse elements of the list(please don't use built-in reverse function).? I have...
pramod shinde
prmdshinde
Offline Send Email
Sep 16, 2007
9:22 pm

Hi Pramod, Sorry to spell your name incorrect last time. The following code uses a recursive call to do a reverse of a list only problem is the tr variable it...
samik chakraborty
samik_126
Offline Send Email
Sep 17, 2007
7:12 am

Hi Promode, This is an easy way of doing a reverse without using car, cdr or ca*d*r family how ever it does not use any recursion. You can think about it. But...
samik chakraborty
samik_126
Offline Send Email
Sep 17, 2007
7:13 am

check the following code .. (defun rev(a) (if (or (null a) (equal a '())) '() (append (rev (cdr a)) (list (first a))))) -- ... Sometimes I wish I was a little...
Rajaram Gaunker
zimbabao
Offline Send Email
Sep 17, 2007
11:51 am

... See what happens when I try to compile your MY-REVERSE - ; While compiling MY-REVERSE: Warning: Free reference to undeclared variable TEMP-RET assumed...
Chaitanya Gupta
icehotcg
Offline Send Email
Sep 18, 2007
5:18 am

Thanks it works..., Is it the same way by which i can find mirror image of the list. ... Expected result is : (((e d)c)(b a)) Pramod K.Shinde ... From: samik...
pramod shinde
prmdshinde
Offline Send Email
Sep 17, 2007
9:33 pm

Thanks samik, i m able to do the reverse function: (defun rev (x) (if (endp x) nil (append (rev (cdr x)) (list (car x))))) ... (d a c b a) Pramod K.Shinde ... ...
pramod shinde
prmdshinde
Offline Send Email
Sep 18, 2007
3:53 am

Thanks a lot to all, This mail-chain has produced at least three ways of doing the same thing and all of them are different and elegant. Great going guys......
samik chakraborty
samik_126
Offline Send Email
Sep 18, 2007
6:58 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help