0

PROLOG我有一个条目的逻辑库(存储在内存中),我必须将其转换为条目列表。

例子:

| ?- rule(A,B).

A = member(_h209,[_h209|_h212])
B = true;

A = member(_h209,[_h211|_h212])
B = member(_h209,_h212);

[member(_h209,[_h209|_h212]),true,member(_h209,[_h211|_h212]),member(_h209,_h212);]

任何人都可以让我知道我怎样才能得到它。

4

1 回答 1

0

something close to your expected result (except the semicolon at end) could be:

rule_list(Rules) :-
     findall([A, B], rule(A, B), L),
     flatten(L, Rules).

A note on _h209, occurring at first position of member: I'm not sure you know the meaning of such symbols. These are variables, and if you interested in mantaining the identities these express, my suggestion isn't correct. Use bagof in such case.

于 2012-04-30T04:55:36.313 回答