?- var(a). - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

?- var(a).

Description:

... Functor, Arity) Succeeds if Term is a term with functor 'Functor' ... X=likes(mary,john),functor(X,Func,Arity). X = likes(mary, john) Func = likes. Arity = 2 ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 7
Provided by: hasa
Category:
Tags: functor | var

less

Transcript and Presenter's Notes

Title: ?- var(a).


1
var(X) Succeeds if X is an unbound
variable. nonvar(X) Succeeds if X is not an
unbound variable.
?- var(a). No ?- nonvar(a). Yes ?- var(X). X
_G179 Yes ?- var(likes(X,Y)). No ?-
?- var(X,Y,Z). No ?- nonvar(X,Y,Z). X
_G233 Y _G236 Z _G239 Yes ?-
nonvar(likes). Yes
2
compound(X) Succeeds if X is bound to a
compound term.
?- compound("this is a string"). Yes ?-
compound('this is a string'). No ?-
compound(X). No ?- Xparents(adam,john,mary),compo
und(X). X parents(adam, john, mary) Yes ?-
compound(967). No ?- compound(1.25). No ?-
compound(compound). No
?- compound(a). No ?- compound(likes(john,mary)).
Yes ?- compound(likes(X,Y)). X _G263 Y _G264
Yes ?- compound(likes(X,Y)-likes(Y,X)). X
_G335 Y _G336 Yes ?- compound(1,2,3,4). Yes
3
functor(Term, Functor, Arity) Succeeds if
Term is a term with functor Functor and
number of arguments Arity.
?- functor(likes(mary,john),Fun,Arity). Fun
likes Arity 2 Yes ?- Xlikes(mary,john),functor
(X,Func,Arity). X likes(mary, john) Func
likes Arity 2 Yes
?- functor(parents(adam,john,mary),F,N). F
parents N 3 Yes ?- functor(X,likes,2). X
likes(_G303, _G304) Yes
4
arg(N,Term,Value) When Term is bound to a
term and N to an integer between 1 and the
number of arguments of Term, Value is
unified with the N-th argument of Term.
?- arg(2,likes(mary,john),X). X john Yes ?-
arg(2,likes(mary,X),john). X john Yes ?-
arg(3,parents(john,george,X),Val). X _G346 Val
_G346 Yes ?- arg(3,parents(john,george,victoria
),Val). Val victoria Yes
?- arg(3,1,2,3,Val). No ?- arg(2,Y,X). ERROR
arg/3 Arguments are not
sufficiently instantiated ?- Xlikes(mary,john),ar
g(2,X,Y). X likes(mary, john) Y john Yes
5
An Example (Clocksin and Mellish)
nought
Tic-Tac-Toe
A 3 X 3 board (9 squares on the board)
Representing the game board
cross
board(Sq1,Sq2,Sq3,Sq4, Sq5, Sq6, Sq7, Sq8,
Sq9) board(o, Sq2, Sq3, Sq4, x, o, Sq7, Sq8, x)
board(Sq1,Sq2,Sq3,Sq4,Sq5,Sq6,Sq7,Sq8,Sq9). boar
d(o,Sq2,Sq3,Sq4,x,o,Sq7,Sq8,x).
6
forced_move(Board,Sq)- aline(Squares),
threatening(Squares,Board,Sq), !.
aline(1,2,3). aline(4,5,6). aline(7,8,9). al
ine(1,4,7). aline(2,5,8). aline(3,6,9). ali
ne(1,5,9). aline(3,5,7).
threatening(X,Y,Z, B, X)- empty(X,B),
cross(Y,B), cross(Z,B). threatening(X,Y,Z, B,
Y)- empty(Y,B), cross(X,B), cross(Z,B). threateni
ng(X,Y,Z, B, Z)- empty(Z,B), cross(X,B),
cross(Y,B). empty(Sq,Board)- arg(Sq, Board,
Val), var(Val). cross(Sq,Board)- arg(Sq, Board,
Val), nonvar(Val), Val x. nought(Sq,Board)-
arg(Sq, Board, Val), nonvar(Val), Val o.
Write a Comment
User Comments (0)
About PowerShow.com