我无法让我的 Prolog DCG 与 atom concat 一起工作 [英] I can't get my Prolog DCG working with atom concat
本文介绍了我无法让我的 Prolog DCG 与 atom concat 一起工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法让这个 Prolog DCG 代码工作:
I can't get this Prolog DCG code working:
String1=" ",string_codes(String1,Codes),phrase(spaces(Output),Codes).
spaces(XXs) -->
[X], {X=32}, spaces(Xs),
{char_code(Ch,X), atom_concat(Ch,Xs,XXs)}, !. %%Space
spaces([]) --> [].
推荐答案
我觉得改进后的解决方案可能是这样的:
I feel like an improved solution would probably be something like this:
spaces(Spaces) --> " ", spaces(S0), { atom_concat(' ', S0, Spaces) }.
spaces('') --> [].
没有必要问代码 32 的字符是什么,你知道它是一个空格.此外,您的答案中的 [X], {X=32}
比 [32]
更好,而 " "
则更好.
There's no real need to ask what the char is for code 32, you know it's a space. Also, [X], {X=32}
from your answer is better as [32]
, which is still better as " "
.
这篇关于我无法让我的 Prolog DCG 与 atom concat 一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文