Your solution explained: If we reverse the empty list, we obtain the empty list. If we reverse the list [H|T] , we end up with the list obtained by reversing T and concatenating with [H] . To see that the recursive clause is correct, consider the list [a,b,c,d] . If we reverse the tail of this list we obtain [d,c,b] . Concatenating this with [a] yields [d,c,b,a] , which is the reverse of [a,b,c,d]
Another reverse solution:
reverse([],Z,Z). reverse([H|T],Z,Acc) :- reverse(T,Z,[H|Acc]).
call:
?- reverse([a,b,c],X,[]).
For further information please read: http://www.learnprolognow.org/lpnpage.php?pagetype=html&pageid=lpn-htmlse25
Related Posts:
- How do I append lists in Prolog?
- List Length in Prolog
- How do I concatenate two lists in Python?
- Print a list in reverse order with range()?
- How do I concatenate two lists in Python?
- How do I concatenate two lists in Python?
- Inorder Binary Tree Traversal (using Python)
- How to have a set of sets in Python?
- How to concatenate items in a list to a single string?
- Learning Haskell: How to remove an item from a List in Haskell
- How to obtain a subarray in python 3
- creating a reverse method for a python list from scratch
- Editing a Post, 99% CPU?
- Similar posts formatting
- Introductory paragraph only in list of blog posts
- List all categories in options
- WooCommerce Grid / List view
- custom walker wp menu last element
- How to divide and display categories into two columns
- To get list of bottom most or deepest or last child for specified parent category
- List first letter of categories – issue upon spcecial characters (danish letters)
- How do I create an alphabetically organized glossary of links?
- Generate a nested list of all posts, sorted first by year, then by month
- adding a #hash to each link in list_pages()?
- How correct list-style displayed in firefox? [closed]
- Output categories in something different than a list
- Wrap Meta Box with and for each new line
- get_all_category_ids for bookmark
- Add thumbnails in ‘li’ list
- List child pages alphabetically
- How to make a text string into a bullet list [closed]
- TypeError: list indices must be integers or slices, not str
- TypeError: list indices must be integers or slices, not list
- Is there a short contains function for lists?
- appending list but error ‘NoneType’ object has no attribute ‘append’
- Check if something is (not) in a list in Python
- Convert Set to List without creating new List
- Finding and replacing elements in a list
- ValueError: max() arg is an empty sequence
- Getting a map() to return a list in Python 3.x
- finding the maximum length of lists in c#
- Append integer to beginning of list in Python
- List comprehension on a nested list?
- Union of two lists in Python
- Python: Array v. List
- What’s the idiomatic syntax for prepending to a short python list?
- Converting Dictionary to List?
- How to deep copy a list?
- Alphabet range in Python
- How to check if a string is a substring of items in a list of strings?
- How do I check if a list is empty?
- IndexError: list index out of range and python
- How to iterate through two lists in parallel?
- How to remove \n from a list element?
- Printing an array in C++?
- How to print out all the elements of a List in Java?
- How do I concatenate const/literal strings in C?
- How do I check if there are duplicates in a flat list?
- Type List vs type ArrayList in Java
- Defining lists as global variables in Python
- Android TextView : “Do not concatenate text displayed with setText”
- Are 2 dimensional Lists possible in c#?
- Python 2: AttributeError: ‘list’ object has no attribute ‘strip’
- Appending a list in a loop (R)
- How to make a set of lists
- How to create a numpy array of lists?
- numpy array concatenation error: 0-d arrays can’t be concatenated
- Determine if 2 lists have the same elements, regardless of order? [duplicate]
- Building a list inside a list in python
- Removing default image size list in Media Box
- How to put last edited entry on top of the blog-post list?
- how to change appearence of the content of default post list columns?
- How to find the number of Tags a post has?
- wordpress wp_list_categories
- WordPress’ visual editor messing up my (nested) lists (and other things as well)
- wp alchemy multiple image uploader output images to template
- Displaying terms by first letter
- Adding (blog-specific) links to “My Sites” admin page
- Display the last post by each category?
- List all categories with featured image from post?
- Authors list Pagination : result set from $wpdb->get_results()
- Is a list page usually called an archive page in WordPress?
- new WP_Query all post in a category inside the loop
- Hide specific category from wp_list_categories
- How do I add a separator to my list of terms with get_category
- display widget checkbox selection on frontend
- List sub-taxonomies from current taxonomy
- Efficient way to fetch all archived WPMS blogs
- wp_nav_menu: output featured image of each page listing
- Highlighting Current Category in the Archive and Feeds page
- How to let users create lists of woocommerce products?
- put a list of one post type in other post type to select from it and display selected item in second post type’s single page
- Listing Custom Post Post from certain category
- Add specific class to featured posts
- Create a Page Template Which Displays All Posts by Current User
- Last three posts not being put in order by date. How to fix this?
- How to Create a Frontend Html-list Editable in the Backend?
- add a “list” into add meta box : problem
- Dynamic archive of posts by date
- Insert a group block inside a list item