translate( 1 2 9 one two nine ) prolog programming code example

Example 1: translate( 1 2 9 one two nine ) prolog programming

totext(0, 'zero').
totext(1, 'one').
totext(2, 'two').
totext(3, 'three').
totext(4, 'four').
totext(5, 'five').
totext(6, 'six').
totext(7, 'seven').
totext(8, 'eight').
totext(9, 'nine').

translate([], []).
translate([Head|Rest], [TranslatedHead|TranslatedRest]) :-
   totext(Head, TranslatedHead),
   translate(Rest, TranslatedRest).

Example 2: translate( 1 2 9 one two nine ) prolog programming

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