Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program Define the relation last(item,list) so that item is the last element of the list using concatenate

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

Prolog program Define the relation last(item,list) so that item is the last element of the list using concatenate.

Code for Prolog program Define the relation last(item,list) so that item is the last element of the list using concatenate in Artificial Intelligence

domains
    x = integer
    l = integer*
        
predicates
    concatenate(l,l,l)
    last(x,l)
    
clauses
    concatenate([],List,List).
    
    concatenate([X|List1],List2,[X|List3]) :-
        concatenate(List1,List2,List3).
    
    last(X,List) :-
        concatenate(List,[X],List1),
        write("The new list is ",List1),nl.
        
Output :

Goal: last(3,[2,1,6,3])

The new list is [2,1,6,3,3]
Yes

  
Share: 



Milind Mishra
Milind Mishra author of Prolog program Define the relation last(item,list) so that item is the last element of the list using concatenate is from India.
 
View All Articles

Related Articles and Code:


 
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!