'和'之间有什么区别?在Prolog中? [英] What is the difference between ' and " in Prolog?

查看:127
本文介绍了'和'之间有什么区别?在Prolog中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Prolog的新手,注意到'和'给出了不同的行为,但对原因却感到好奇。特别是在加载文件时,?-['test1.pl']。有效,而?-[ test1.pl]。无效。

I am new to Prolog and noticed that ' and " give different behavior, but am curious as to why. Specifically, when loading a file, ?- ['test1.pl']. works, while ?- ["test1.pl"]. doesn't.

推荐答案

单引号始终是原子。

双引号的含义取决于Prolog标志 double_quotes

The meaning of double quotes depends on the Prolog flag double_quotes:

atom
的值 a = a 。如今,这种用法很少使用。但是您会发现Prolog书中的 [ abc.pl]

atom — with this value "a" = a. Nowadays, this is rarely used. But you will find Prolog books where ["abc.pl"] is written.

代码
a字符代码列表,这通常是默认设置,但会导致非常难以理解的答案,例如

codes — a list of character codes. This is frequently the default, but it leads to very unreadable answers like


?- set_prolog_flag(double_quotes,codes).
true.

?- phrase(("Ja tvoi ",("sluga"|"rabotnik"),"!"), Satz).
Satz = [74,97,32,116,118,111,105,32,115,108,117,103,97,33] ;
Satz = [74,97,32,116,118,111,105,32,114,97,98,111,116,110,105,107,33].

更糟糕的是,如果使用ASCII以外的字符:

Even worse, if you use characters beyond ASCII:


?- phrase(("Я твой ",("слуга"|"работник"),"!"), Satz).
Satz = [1071,32,1090,1074,1086,1081,32,1089,1083,1091,1075,1072,33] ;
Satz = [1071,32,1090,1074,1086,1081,32,1088,1072,1073,1086,1090,1085,1080,1082,33].






字符
—一字符原子列表。 有关详情,请参见


?- set_prolog_flag(double_quotes,chars).
true.

?- phrase(("Ja tvoi ",("sluga"|"rabotnik"),"!"), Satz).
Satz = ['J',a,' ',t,v,o,i,' ',s,l,u,g,a,!] ;
Satz = ['J',a,' ',t,v,o,i,' ',r,a,b,o,t,n,i,k,!].

?- phrase(("Я твой ",("слуга"|"работник"),"!"), Satz).
Satz = ['Я',' ',т,в,о,й,' ',с,л,у,г,а,!] ;
Satz = ['Я',' ',т,в,о,й,' ',р,а,б,о,т,н,и,к,!].

此表示法提供了更具可读性的答案,并且是 Scryer ,它使用双引号表示法来更紧凑地显示它们,以打印任何一个一字符原子的列表。对于 SICStus SWI 可以使用以下库进行仿真。

This notation gives more readable answers and is the default in Scryer which displays them even more compactly with the double quote notation for printing any list of one-char atoms. For SICStus and SWI this can be emulated with the following library.


?- use_module(library(double_quotes)).
true.

?- phrase(("Ja tvoi ",("sluga"|"rabotnik"),"!"), Satz).
Satz = "Ja tvoi sluga!" ;
Satz = "Ja tvoi rabotnik!".

?- phrase(("Я твой ",("слуга"|"работник"),"!"), Satz).
Satz = "Я твой слуга!" ;
Satz = "Я твой работник!".

如果在安装 double_quotes.pl 作为库时遇到困难,只需将其放入进入其他Prolog文件的目录,然后说: use_module(double_quotes)。

If you have difficulties installing double_quotes.pl as a library, simply put it into the directory of your other Prolog files and say: use_module(double_quotes).

这篇关于'和'之间有什么区别?在Prolog中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆