I want to write a function in lisp that reverses all elements from the list using map functions but I don't have any idea how to start this.. I think I have to use the built in reverse function somehow.. For example if I have the list (1 2 3 (4 5 6 (7 8 9))) I would get (((9 8 7) 6 5 4) 3 2 1) or if I had the list(1 2 3 (4 5) (6 7)) I would get ((7 6) (5 4) 3 2 1) .. Any help is appreciated!
相关问题
- PHP Recursively File Folder Scan Sorted by Modific
- F#: Storing and mapping a list of functions
- Generating powerset in one function, no explicit r
- How to get coordinates of an svg?
- recursion, Python, countup, countdown
相关文章
- Recursively replace keys in an array
- Python: Maximum recursion depth exceeded when prin
- Is recursion good in SQL Server?
- How does this list comprehension over the inits of
- Find all subfolders of the Inbox folder using EWS
- Does learning one Lisp help in learning the other?
- What is the definition of “natural recursion”?
- How do I write a macro-defining macro in common li
Here is a version that works for me in Common-Lisp.
Output:
Mapcar is a function that takes another function as its first parameter and a list as its second parameter. It then calls that function on each element of the list. It returns a list of all of the answers. So after I use 'mapcar' to reverse all of the sublists, I call 'reverse' again to reverse the bigger list.
The function that it calls on each sublist is 'reverse-list'. This checks if the list is an atom. If it is, then it returns itself. If it's a list, then it calls mapcar again on each element in the list, then reverses the result.
Just a quick answer, not sure about efficiency/elegancy: