Counter-intuitive behavior of min_member/2

后端 未结 6 1441
一个人的身影
一个人的身影 2021-01-04 16:40

min_member(-Min, +List)

True when Min is the smallest member in the standard order of terms. Fails if List is empty.

?- min_member(3, [1,2,X]).
X = 3         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-04 16:42

    This is a common property of many (all?) predicates that depend on the standard order of terms, while the order between two terms can change after unification. Baseline is the conjunction below, which cannot be reverted either:

    ?- X @< 2, X = 3.
    X = 3.
    

    Most predicates using a -Value annotation for an argument say that pred(Value) is the same as pred(Var), Value = Var. Here is another example:

    ?- sort([2,X], [3,2]).
    X = 3.
    

    These predicates only represent clean relations if the input is ground. It is too much to demand the input to be ground though because they can be meaningfully used with variables, as long as the user is aware that s/he should not further instantiate any of the ordered terms. In that sense, I disagree with @mat. I do agree that constraints can surely make some of these relations sound.

提交回复
热议问题