?
Solved

reverse a list

Posted on 2004-10-05
7
Medium Priority
?
298 Views
Last Modified: 2010-04-17
how to reverse a list in Lisp apart of using it's buid-in function reverse????


thanks
0
Comment
Question by:nguln
  • 3
5 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 12224700
Is this a homework problem?
You probably want to use car cdr and cons
0
 
LVL 1

Expert Comment

by:swdld
ID: 12225406
please what is "list in lisp" ???
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12230495
LISP is a functional programming language designed to use lists.  Lists are defined by brackets as so:
( "a" 2 "c")
and embedded as so:
("a" (1 "b") ("c" ("d")))

which is a list with three elements, where the second element is a list with two elements, and the third element is a list with two elements, the second of which is a list.  Actually, only result lists display like that.  To define a list, use the List function, like this:

(List "a" 2 "c")

where you want the list elements to be the atoms "a", 2, and "c".
0
 
LVL 4

Accepted Solution

by:
Rick_Townsend earned 80 total points
ID: 12230531
As for answering the posted question, ozo is right, use car to get the first element of the list, and cdr to get the rest of the list.  Build your result using cons, where the two parameters will be a recursive call to your reverse function and the head of the current list.
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12230543
The solution is elegant, but I think EE rules are that we can't give actual homework answers, only answer questions and help with debugging your algorithm.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Screencast - Getting to Know the Pipeline

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question