开发者

translate(list1, list2) in prolog

I was trying a functor translate([3,5,1,3],[three,five,one,three]) which does the operation of printing numbers. I get a strange warning while executing like this,

35 ?- translate([1,2,3],[a,b,c]). ERROR: write/2: stream `a' does not exist

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).

What exactly is the problem? This is the expected value.

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

a = one b = two c = three

Yes


Variables need to be uppercase:

translate([1,2,3],[A,B,C]).

When you enter the translate([Head1|Tail1],[Head2|Tail2]) clause, a unifies with Head2, and then you try to satisfy write(Head2, "="), which is write(a, "=").

write/2 takes as first argument a Stream and writes the second argument to that Stream.

Presumably you want to use - if you want output at all - something like

writef('Head2 = %w', [Head2])

(I got the formatting from here.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜