How to write a rule that finds a number using integer / 1?

I am writing a rule that searches for a specific integer. I suggested that I could write something like this

find_number(X):-
    integer(X),
    X > 1, X < 5.

Then expect the result of the query to integer(X)result in X=2, X=3, X=4, false.. Instead, I get the result false. The only way I found this rule is to use numlist/3this

find_number(X):-
    numlist(2, 4, NumList),
    member(X, NumList).

Can someone explain why this is?

+4
source share
2 answers

Your arguments would be perfectly valid if if integer/1were an actual relation that satisfies the underlying logical properties.

, P :

P (& sigma; (T)) & sigma; term T, , P (T) .

, , pure Prolog.

, integer/1 not .

, , :

?- integer(3).
true.

:

?- integer(X).
false.

? .

, integer/1.

, - , Prolog , Prolog.

CLP (FD) ().

, GNU Prolog :

good_number(X) :-
        X #> 1,
        X #< 5.

:

| ?- good_number(X).
X = _#2(2..4)

| ?- good_number(X), fd_labeling([X]).
X = 2 ? ;
X = 3 ? ;
X = 4

, ! , , "":

| ?- good_number(3).
yes

Prolog . . .

+4

false, integer/1 , , , , , , , .

between/2 :

find_number(X):-between(2,4,X).

This will return:

?- find_number(X).
X = 2 ;
X = 3 ;
X = 4.
+1
source

Source: https://habr.com/ru/post/1680514/


All Articles