Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to define the relation translate(List1, List2) to translate a list of numbers between 0 and 9

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

Define the relation translate(List1, List2) to translate
a list of numbers between 0 and 9.
E.g. if the input is translate([1,2,3], [A,B,C]) then
the output should be A=one, B=two, C=three.
Use the relations means (0, zero), means (1, one) and so on.

Code for Prolog program to define the relation translate(List1, List2) to translate a list of numbers between 0 and 9 in Artificial Intelligence

domains

    list1=integer*
    list2=symbol*

    
predicates

    translate(list1,list2)
    means(integer,symbol)

    
clauses
    
    translate([],[]).
    
    translate([],_):-
        write("\nError in Input").
    
    translate(_,[]):-
        write("\nError in Input").
            
    translate([Head1|Tail1],[Head2|Tail2]):-
        write(Head2," = "),
        means(Head1,Name),
        write(Name,"\n"),
        translate(Tail1,Tail2).
        

    means(0,zero).
    
    means(1,one).

    means(2,two).

    means(3,three).

    means(4,four).

    means(5,five).

    means(6,six).

    means(7,seven).

    means(8,eight).

    means(9,nine).
                                            

OUT PUT
=======

Goal: translate([1,2,3],[a,b,c])

a = one
b = two
c = three

Yes

-------------------------------------

Goal: translate([1,2,3,4,5,6,7,8,9],[a,b,c,d,e,f,g,h,i])

a = one
b = two
c = three
d = four
e = five
f = six
g = seven
h = eight
i = nine

Yes
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to define the relation translate(List1, List2) to translate a list of numbers between 0 and 9 is from India.
 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in Artificial Intelligence:


 
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!