序言术语到字符串
我有一个像这样的序言列表:
[p(X,Y,Z),r(H,G,K)]
我想转换它 变成这样:
'p(X,Y,Z)r(H,G,K)'
它只是一个谓词列表,应该转换为字符串。
你有什么想法吗? (我使用序言)
i have a prolog list like this:
[p(X,Y,Z),r(H,G,K)]
and i want convert it
into this:
'p(X,Y,Z)r(H,G,K)'
it is just a list of predicate, that should be transformed into a string.
Do you have any idea? ( I use prolog)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这样做是不可能的。声明变量后,其名称将丢失以供进一步处理。
编辑:
如果您不介意丢失名称,这样的事情是可能的。至少在 SWI-Prolog 中:
I think doing that is not possible. After you declare a variable, its name is lost for further processing.
EDIT:
Something like this is possible, if you don't mind losing the names. At least in SWI-Prolog:
您可以使用
variable_names
选项读取术语,该选项为您提供读取术语中 Name=Variable 对的列表。所以也许这就是您所需要的。这是一个命令行,它读取该术语,然后将变量与其名称统一,最后按照您在问题中指定的方式将结果打印到原子中。
请注意,它会修改读取术语,因此您可能需要先复制它 (
copy_term/2
)。You can read terms using the
variable_names
option, which gives you a list of Name=Variable pairs in the read term. So maybe this is what you need.Here is a command line that reads the term, then unifies the variables with their names and finally prints the result into an atom in the way that you specified in your question.
Note that it modifies the read term, so you might want to make a copy of it first (
copy_term/2
).