Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables type in Prolog

Status
Not open for further replies.

Bl1nD

Programmer
Jan 18, 2006
2
RO
How can you tell the program tha variable X is has a certin type ...

This is actually the problem ...

3. Define a predicate is_between(X , Y , N) meaning "N is between X and Y" and working like in the example below (there is a predefined PROLOG predicate called between that has the same behavior):
?- is_between(1,5,3).

Yes

?- is_between(1,5,7).

No

?- is_between(1,5,N).

N = 1 ;

N = 2 ;

N = 3 ;

N = 4 ;

N = 5 ;

No

ps: i'm a newbie .. if you didn't noticed :p :p
 
It may solve by this program.

is_between(X, Y, N) :-
X - 1 < Y,
N is X.

is_between(X, Y, N) :-
X - 1 < Y,
is_between(X + 1, Y, N).

example:

?- is_between(3, 11, 1).
no

?- is_between(3, 11, 3).
yes

?- is_between(3, 11, 7).
yes

?- is_between(3, 11, 11).
yes

?- is_between(3, 11, 15).
no

?- is_between(2, 4, N).
N = 2 ;
N = 3 ;
N = 4 ;
no

?- is_between(6, 6, N).
N = 6 ;
no

?- is_between(4, 2, N).
no
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top