Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to add an element in a last position in given list

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

Prolog program to add an element in a last position in given list.

Code for Prolog program to add an element in a last position in given list in Artificial Intelligence

domains

    list=symbol*

    
predicates

    add(symbol,list,list)

    
clauses

    add(X,[],[X]).
    
    add(X,[Y|Tail],[Y|Tail1]):-
        add(X,Tail,Tail1).
        

OUT PUT
=======

Goal: add(e,[a,b,c,d],NewList)

NewList=["a","b","c","d","e"]

1 Solution
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to add an element in a last position in given 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!