相关疑难解决方法(0)

AUBUC的Prolog联盟

我最近开始学习Prolog,我无法解决如何组合三个列表的问题.

我能够组合2个列表:

%element
element(X,[X|_]).
element(X,[_|Y]):-
               element(X,Y).

%union

union([],M,M).
union([X|Y],L,S) :- element(X,L),union(Y,L,S).
union([X|Y],L,[X|S]) :- (not(element(X,L))),union(Y,L,S).
Run Code Online (Sandbox Code Playgroud)

有人可以帮我吗?

list prolog

20
推荐指数
2
解决办法
2605
查看次数

实现一个 Prolog 谓词,说明一个元素是否属于一个列表。非数字列表的问题

我正在为大学考试学习 Prolog,但我在这个练习中遇到了问题:

not_member(X,L)如果元素X不属于列表,则实现为 TRUE的谓词L

如果我的推理是正确的,我已经找到了解决方案:

% FACT (BASE CASE): It is TRUE that X is not in the list if the list is empty.
not_member(_,[]).

% RULE (GENERAL CASE): If the list is non-empty, I can divide it in its Head
%   element and the sublist Tail. X does not belong to the list if it is different 
%   from the current Head element and if it does not belong to the sublist Tail.
not_member(X,[Head|Tail]) …
Run Code Online (Sandbox Code Playgroud)

prolog prolog-dif

5
推荐指数
2
解决办法
7352
查看次数

标签 统计

prolog ×2

list ×1

prolog-dif ×1