我是新来的,是利用博客。
I have been reading some example program to execute query on group of related data. But in order to infer from facts with similar structure, they wrote many predicates like search_by_name
,search_by_point
, which are partly duplicated.
% working search in example
search_by_name(Key,Value) :-
Key == name,
sname(ID,Value),
point(ID,Point),
write(Value),write(Point),nl.
当我试图用更笼统的措辞来取代它们时:
% a more general search I want to write
% but not accepted by BProlog
search_by_attr(Key,Value) :-
Key(ID,Value),
sname(ID,Name),
point(ID,Point),
write(Name),write(Point),nl.
error arised:
| ?- consult( students.pl )
consulting::students.pl
** Syntax error (students.pl, 17-21)
search_by_attr(Key,Value) :-
Key<<HERE>>(ID,Value),
sname(ID,Name),
point(ID,Point),
write(Name),write(Point),nl.
1 error(s)
我这样做是错误的,还是不可能在道歉中采取这种态度?
守则和实例数据可在https://gist.github.com/2426119查询。