正如名字一样double_quotes
意味着,这个标志如何影响双引号 (i.e.: "
) 进行处理。
无论此类报价是否与 DCG 一起使用,这都适用。但是,它在与 DCG 结合使用时特别有用,因为您可以使用:
?- phrase(nt(NT), "test").
从而自动将要解析的短语视为字符列表(在本例中:[t,e,s,t]
)。这对于交互式测试用例来说非常有用。
The 错误回答 https://stackoverflow.com/a/8269897/1613573您链接的内容很好地解释了这一点。另请注意答案中的以下引用:
This notation [using chars!] gives more readable answers. It can be even more compactly displayed since the double quote notation can be used for printing any list of one-char atoms.
很清楚chars产生比以下内容更易读的答案codes
。例如:
?- Xs = "hello".
Xs = [h, e, l, l, o].
与,与codes
:
?- Xs = "hello".
Xs = [104, 101, 108, 108, 111].
(Ahem.)
Historically, Han shot first https://en.wikipedia.org/wiki/Han_shot_first chars came first! Only later, this was changed to using codes by default. A quite unfortunate choice, in my view. Other languages like Haskell work like Prolog originally did:
Hugs> :t last
last :: [a] -> a
Hugs> :t "test"
"test" :: String
Hugs> last "test"
't'