Prolog文件操作问题 [英] Prolog file manipulation problem

查看:181
本文介绍了Prolog文件操作问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用swi序言和这样的代码. 我从文件中读取了数据谓词,其arity计数可以更改.我如何概括它.例如,如果data(a1,b1,c1)写入文件,如何找到解决方案?你有什么主意吗?

I use swi prolog and my code like this. I read data predicate from file and its arity count can change. How can I generalize it. For example, If data(a1,b1,c1) writes in the file, how can I find solution? Do you have any idea?

>    basla:-consult('test.pl'),
>          answer(L1,L2,L3,L4,L5),
>          list_to_set(L1, X),
>        
>          write(X).
>     answer(L1,L2,L3,L4,L5):-
>       findall(First, data(First,_,_,_,_),L1),
>       findall(Second, data(_,Second,_,_,_),L2),
>       findall(Third, data(_,_,Third,_,_),L3).

推荐答案

如果谓词的Arity似乎发生了变化,最好将其设为Arity并为其提供一个列表参数.然后,您可以通过调用nth1nth0扩展您的findall查询.

If the arity of a predicate seems to change, it's almost always better to make it arity one and give it a list argument. Your findall queries can then be extended with a call to nth1 or nth0.

这篇关于Prolog文件操作问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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