如何得到术语的概括。序言

时间:2011-09-18 11:44:27

标签: prolog term

例如 - 我有一些条款:

moves(1, [1]).
moves(1, [2]).
moves(1, [3]).

我怎样才能获得下学期?

moves(1, [1,2,3]).

% I have
    moves(1, [1]).
    moves(1, [2]).
    moves(1, [3]).

% I need to write some predicate which
    transform_moves :- 
        % ...
        % ...
        assert(moves(Pos, Arr)),

        % moves(1, [1,2,3]).

1 个答案:

答案 0 :(得分:2)

程序:

:- dynamic moves/2.

moves(1, [1]).
moves(1, [2]).
moves(1, [3]).

transform_moves(Pos) :- 
    findall(Y, moves(Pos, [Y]), L), 
    retractall(moves(Pos, _)),
    assert(moves(Pos, L)).

呼叫:

?- transform_moves(1).