开发者

How to get generalization of term. Prolog

开发者 https://www.devze.com 2023-04-05 11:39 出处:网络
F开发者_JAVA百科or example - I have some terms: moves(1, [1]). moves(1, [2]). moves(1, [3]). How can I get next term?

F开发者_JAVA百科or example - I have some terms:

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

How can I get next term?

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]).


Program:

:- 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)).

Call:

?- transform_moves(1).
0

精彩评论

暂无评论...
验证码 换一张
取 消