Error "illegal variable type for this position " in prolog

1.1k Views Asked by At

I try to make a search of animal, who has this property, but I have an error "illegal variable type for this position ".How to solve it?

domains
type=symbol
object=symbol
property=symbol
value=symbol
parent=symbol
predicates
nondeterm is_a(type, parent) 
nondeterm has_prop(object, property, value) 
nondeterm has_property(object, property, value) 
clauses
is_a(dog,wolf).
is_a(dingo,wolf).
is_a(wolf,volki).
is_a(coyote,volki).
is_a(jackal,volki).
is_a(volki,dogs).
is_a(fox,dogs).
is_a(arctic_fox,dogs).

has_prop(dogs, travel, walk). 
has_prop(dogs, food_for_child, milk).  
has_prop(volki, size, medium). 
has_prop(volki, color, brown). 
has_prop(arctic_fox, color, white). 
has_prop(arctic_fox, size, small). 
has_prop(fox, color, orange). 
has_prop(fox, size, small). 
has_prop(wolf, color, grey). 
has_prop(wolf, size, large). 
has_prop(dog, color, brown). 
has_prop(dog, size, small). 
has_prop(dingo, color, orange). 
has_prop(dingo, size, medium). 



has_property(Object, Property, Value):-
has_prop(Object, Property, Value). 
has_property(Object, Property, Value):-
is_a(Object,Parent), 
has_property(Parent, Property, Value).

goal
has_property(X,size,medium).

I have an error "illegal variable type for this position " at this line:

is_a(Object,Parent), 
2

There are 2 best solutions below

0
Ivan Skotsyk On BEST ANSWER

The problem was in types and variables. I delete domains and work with simple types.

Right Code:

predicates
nondeterm is_a(symbol, symbol) 
nondeterm has_prop(symbol, symbol, symbol) 
nondeterm has_property(symbol, symbol, symbol) 
clauses
is_a(dog,wolf).
is_a(dingo,wolf).
is_a(wolf,volki).
is_a(coyote,volki).
is_a(jackal,volki).
is_a(volki,dogs).
is_a(fox,dogs).
is_a(arctic_fox,dogs).

has_prop(dogs, travel, walk). 
has_prop(dogs, food_for_child, milk).  
has_prop(volki, size, medium). 
has_prop(volki, color, brown). 
has_prop(arctic_fox, color, white). 
has_prop(arctic_fox, size, small). 
has_prop(fox, color, orange). 
has_prop(fox, size, small). 
has_prop(wolf, color, grey). 
has_prop(wolf, size, large). 
has_prop(dog, color, brown). 
has_prop(dog, size, small). 
has_prop(dingo, color, orange). 
has_prop(dingo, size, medium). 


has_property(O, Property, Value):-
has_prop(O, Property, Value). 
has_property(O, Property, Value):-
is_a(O,Parent), 
has_property(Parent, Property, Value).

goal
has_property(X,size,medium).
10
CapelliC On

Sorry I don't have Visual Prolog available for testing, so I'm not really sure about the solution, but I think the problem is that you should make clear that domains and predicates elements are ground terms. So I suggest to either make them lowercase, or bracket them with hyphens, otherwise they are variables:

domains
 type=symbol
 object=symbol
...

predicates
 is_a(type, parent) 
...

or

domains
 'Type'=symbol
 'Object'=symbol
...

predicates
 is_a('Type', 'Parent') 
...

edit

If you have SWI-Prolog available, just comment out from start of file to domains included. Or see this notebook on SWISH.