Unexpected output from a Prolog script

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 it to inHands.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?

+3
source share
1 answer

Turns out I should use single quotes as follows:

write('My text').
0
source

Source: https://habr.com/ru/post/1732661/


All Articles