在序言中翻译(列表1,列表2)
我正在尝试使用函子translate([3,5,1,3],[三,五,一,三])来执行打印数字的操作。在像这样执行时,我收到一个奇怪的警告,
35 ?-translate([1,2,3],[a,b,c])。 错误:write/2:流“a”不存在
domains
list1=integer*
list2=symbol*
谓词
translate(list1,list2)
means(integer,symbol)
子句
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).
到底是什么问题?这是预期值。
翻译([1,2,3],[a,b,c])
a = 1 b = 2 c = 3
是
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
变量需要大写:
当您输入
translate([Head1|Tail1],[Head2|Tail2])
子句时,a
与Head2
统一>,然后尝试满足write(Head2, "=")
,即write(a, "=")
。write/2 将 Stream 作为第一个参数,并将第二个参数写入该 Stream。
大概你想使用 - 如果你想要输出 - 类似于
(我从 此处。)
Variables need to be uppercase:
When you enter the
translate([Head1|Tail1],[Head2|Tail2])
clause,a
unifies withHead2
, and then you try to satisfywrite(Head2, "=")
, which iswrite(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
(I got the formatting from here.)