开发者

Unexpected output of a Prolog script

开发者 https://www.devze.com 2022-12-20 05:55 出处:网络
leftHand(empty). rightHand(empty). inHands :- write(\"Left hand:\"), nl, leftHand(X), tab(2), write(X), nl, nl,
leftHand(empty).
rightHand(empty).

inHands :-
    write("Left hand:"),
    nl,
    leftHand(X),
    tab(2),
    write(X),
    nl,
    nl,
    write("Right开发者_开发问答 hand:"),
    rightHand(Y),
    tab(2),
    write(Y),
    nl.

I expect inHands. to return something like this:

Left hand:
  empty

Right hand:
  empty

However, this is what I saw:

 24 ?- inHands.
[76, 101, 102, 116, 32, 104, 97, 110, 100, 58]
  empty

[82, 105, 103, 104, 116, 32, 104, 97, 110, 100, 58]  empty
true.

What am I doing wrong here?


Turns out I have to use single quotes like this:

write('My text').
0

精彩评论

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

关注公众号