.如何在Prolog中的写入谓词中写入单引号( ' )?
我想在程序的开头添加简短的信息,我就像这样
message :-
nl,nl,
write(' To start type '), nl,
write(' ?- solve(Input1,Input2,Output3) '), nl.
:- message.
这很好......但我需要 write(' ?-solve('Input1','Input2',Output3) '), nl 所以当我运行程序时它应该打印 开始输入 ?- 解决(' 输入1 ' ,' 输入2 ' ,Output3 )
提前感谢:)
I want to add short info in the beginning of the program and i goes like this
message :-
nl,nl,
write(' To start type '), nl,
write(' ?- solve(Input1,Input2,Output3) '), nl.
:- message.
And this is fine...but i need write(' ?- solve('Input1','Input2',Output3) '), nl
so when i run the program it should print
To start type
?- solve(' Input1 ' ,' Input2 ' ,Output3 )
thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用反斜杠转义引号。
例如,要输出一个单单引号:
作为一般规则,您当然应该完全避免副作用完全。一个好的解决方案是使用 DCG 来描述输出。这使得它适合测试用例,如果输出仅出现在终端上,则很难编写测试用例。
write/1
特别很少使用。如果您确实需要输出某些内容,请使用format/2
。如果您了解 DOS,这听起来很可怕,但事实并非如此。format/2
的一个重要优点是,它可以让您方便地将静态文本与灵活的参数进行网格化,例如:Yielding:
请注意,在这种情况下甚至没有出现单引号的问题。
"
的类似问题可以通过使用\
再次解决:Escape the quote with backslash.
For example, to output a single single-quote:
As a general rule, you should of course avoid side-effects entirely. A good solution is to describe the output using a DCG. This makes it amenable to test cases, which are hard to write if output only appears on the terminal.
write/1
is particularly rarely used. If you really need to output something, useformat/2
. This sounds scary if you know DOS, but it really isn't.An important advantage of
format/2
is that it lets you conveniently mesh static text with flexible arguments, for example:Yielding:
Note that the issue of single quotes didn't even arise in this case. The analogous issue with
"
can again be solved by using\
: