Skip to content

Instantly share code, notes, and snippets.

@jokester
Created April 20, 2012 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jokester/2426119 to your computer and use it in GitHub Desktop.
Save jokester/2426119 to your computer and use it in GitHub Desktop.
snippet for "why can't I subtitude functor with variable in a predicate" @ stackoverflow
% facts : sname(ID,NAME)
sname(1,ada).
sname(2,bob).
% facts : point(ID,POINT)
point(1,80).
point(2,81).
% 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.
% a working one
search_by_attr(Key,Value) :-
call(Key,ID,Value),
sname(ID,Name),
point(ID,Point),
write(Name),write(Point),nl.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment