Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to reverse a list

Posted By: Milind Mishra     Category: Artificial Intelligence     Views: 10096

Prolog program to reverse a list.

Code for Prolog program to reverse a list in Artificial Intelligence

domains
    list=integer*
predicates
    reverse_list(list,list)
    reverse(list,list,list)
clauses
    
    reverse_list(Inputlist,Outputlist):-
    reverse(Inputlist,[],Outputlist).    
    reverse([],Outputlist,Outputlist).    

    reverse([Head|Tail],List1,List2):-
        reverse(Tail,[Head|List1],List2).


Output :

Goal: reverse_list([1,2,
3],X)                   
X=[3,2,1]               
1 Solution              
Goal:                   
  
Share: 


Didn't find what you were looking for? Find more on Prolog program to reverse a list Or get search suggestion and latest updates.

Milind Mishra
Milind Mishra author of Prolog program to reverse a list is from India.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!