I have database which consists of list of trees and facts about those trees. For example:
softness(soft).
softness(hard).
softness(veryhard).
color(gray_brown).
color(soft_red).
color(light).
color(dark).
wood(oak, leafes(leafed), softness(hard), color(gray_brown), on_touch(smalltexture)).
And I'm trying to make rule which will ask user input on specific parameters of tree and then seek for appropriate one. Like this.
what_wood(A, B):-
wood(A, B, _, _, _);
wood(A, _, B, _, _);
wood(A, _, _, B, _);
wood(A, _, _, _, B);
wood(A, B, _, _); %I have one tree with three parameters =/
wood(A, _, B, _);
wood(A, _, _, B).
what_wood(A) :-
write('Leafes: '), read(X), what_wood(A, leafes(X)),
write('Softness: '), read(Y), what_wood(A, softness(Y)),
write('Color: '), read(Z), what_wood(A, color(Z)),
write('On touch: '), read(Q), what_wood(A, on_touch(Q)).
So my question - if user wants to specify parameter as "any" is there a way to do something like this?
leafes(leafed).
leafes(coniferous).
leafes(any):-
leafes(X). %this one doesn't work. Prints false
%leafes(leafed);leafes(coniferous). %Of course this doesn't work too.
(Sorry for my English :) )
=====UPDATE=====
I ended up with this code which works fine thanks to you :) Will add check for user input also.
wood(oak, leafed).
wood(oak, hard).
wood(oak, gray_brown).
wood(oak, smalltexture).
wood(beech, leafed).
wood(beech, hard).
wood(beech, soft_red).
wood(beech, largetexture).
wood(yew, leafed).
wood(yew, veryhard).
wood(yew, dark).
...
what_wood(A, B, C, D, E):-
wood(A, B), wood(A, C), wood(A, D), wood(A, E).
what_wood(A) :-
write('Leafes: '), read(X), convert(X, Leaves),
write('Softness: '), read(Y), convert(Y, Softness),
write('Color: '), read(Z), convert(Z, Color),
write('On touch: '), read(Q), convert(Q, OnTouch),
what_wood(A, Leaves, Softness, Color, OnTouch).
convert(any, _) :-
!.
convert(Attrib, Attrib).
This code returns same answers like
A = oak ;
A = oak ;
...
A = beech ;
A = beech .
But this is other story which have nothing to do with current question.
?- leafes(X).
Variables that occur in queries are existentially quantified, i.e. "Is there something that is a 'leafes'?" If you're not interested in the particular answer you can also use_
i.o.X
. – Wouter Beekleafes(any)
you are asking about one fact with no variables.leafes(Any)
is really the correct way to query it. Your example is also an infinite loop. It doesn't show "false" but infinitely loops with successive "true" results. – lurker