?
Solved

reverse a list

Posted on 2004-10-05
7
Medium Priority
?
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 84

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Six Sigma Control Plans

762 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