简体   繁体   English

测试该术语是不同变量的列表

[英]Test that term is a list of distinct variables

What is the most compact and canonical way in ISO Prolog to test for a list of distinct variables? ISO Prolog中用于测试不同变量列表的最紧凑和规范的方法是什么? Let's call this meta-logical predicate is_varset/1 . 我们称这个元逻辑谓词为is_varset/1

So it should succeed if its argument is a list of variables that are all different. 因此,如果它的参数是一个完全不同的变量列表,它应该会成功。 Note that a list always contains a [] at its end. 请注意,列表的末尾始终包含[] If a variable is at the end, we call this a partial list (which is thus not a list). 如果变量在最后,我们将其称为部分列表 (因此不是列表)。 And if a non-variable term occurs as a suffix that is neither [] nor a variable, then this is neither a partial list nor a list . 如果一个非变量项作为既不是[]也不是变量的后缀出现,那么这既不是部分列表也不是列表

A notable special case of a term being neither a partial list nor a list are infinite lists . 术语既不是部分列表也不是列表的一个值得注意的特殊情况是无限列表 They contain at least two suffixes that are identical, actually they then possess infinitely such suffixes. 它们包含至少两个相同的后缀,实际上它们拥有无限的后缀。 Infinite lists are out of scope of the standard — all attempts to create them result in a STO unification whose result is undefined. 无限列表超出了标准的范围 - 所有创建它们的尝试都会导致STO统一,其结果是未定义的。 Still, some systems support them, so ideally for those infinite lists, is_varset/1 should fail finitely. 尽管如此,有些系统支持它们,因此理想情况下,对于那些无限列表, is_varset/1应该有限地失败。

?- is_varset([A|nonlist]).
false.

?- is_varset([A,B]), is_varset([B,A]).
true.

?- is_varset([A,B,A]).
false.

?- is_varset([A,f(B)]).
false.

?- is_varset([A|_]).
false.

?- L = [_|L], is_varset(L).  % may loop, should rather terminate
false.

Here is an overview of the built-ins in ISO/IEC 13211-1:1995 including Cor.2:2012. 以下是ISO / IEC 13211-1:1995中内置插件概述,包括Cor.2:2012。

SWI-Prolog中的这个简单定义似乎可以满足要求

is_varset(Vs) :- /*is_list(Vs),*/ term_variables(Vs, T), T == Vs.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM