• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

reverse a list

how to reverse a list in Lisp apart of using it's buid-in function reverse????

  • 3
1 Solution
Is this a homework problem?
You probably want to use car cdr and cons
please what is "list in lisp" ???
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".
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.
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now