在序言中翻译(列表1,列表2)

发布于 2024-12-05 04:02:41 字数 826 浏览 0 评论 0原文

我正在尝试使用函子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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余厌 2024-12-12 04:02:41

变量需要大写:

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

当您输入 translate([Head1|Tail1],[Head2|Tail2]) 子句时,aHead2 统一>,然后尝试满足 write(Head2, "="),即 write(a, "=")

write/2 将 Stream 作为第一个参数,并将第二个参数写入该 Stream。

大概你想使用 - 如果你想要输出 - 类似于

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

(我从 此处。)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文