减去但给出参数,不应该删除

时间:2015-10-24 15:34:02

标签: list prolog

我想使用谓词subtract删除所有非列表的列表项。

显示预期答案的示例查询:

?- subtract([1,2,[3],[],4,5,[8]], ..., Xs).
Xs = [[3],[],[8]].

我该怎么做? 谢谢!

2 个答案:

答案 0 :(得分:1)

MYUtils.isIOS = function(){ return navigator.userAgent.match(/(iPad|iPhone|iPod)/g); }; var ios = MYUtils.isIOS(); 与已确定的测试谓词tfilter/3一起使用:它是单调的!

list_t/2

示例查询:

list_t(Xs,T) :-
   (  nonvar(Xs)
   -> (  nil_or_cons(Xs)
      -> T = true
      ;  T = false
      )
   ;  T = true , nil_or_cons(Xs)
   ;  T = false, freeze(Xs,\+nil_or_cons(Xs))
   ).

nil_or_cons([]).
nil_or_cons([_|_]).

答案 1 :(得分:1)

我的old answer显然不正确。

为什么?它将[_|non_list]之类的术语归为列表 ...不好!

为什么? 非递归 nil_or_cons_t/2可能太浅了。

该怎么办?改为使用递归 reified predicate list_t/2