Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use a variable as predicate?

Status
Not open for further replies.

Neophyte1981

Programmer
Dec 28, 2008
2
NL
Is there a way to use a variable as a predicate?

For instance
Code:
test(Pred, Var) :- Pred(Var).
Then asking
Code:
test(not, true).
should yield false. Is this is possible? Do I need to use an eval() type function?

With kind regards, Patrick
 
You can do this kind of thing :
Code:
mult(X, Y) :-
	Y is 2 * X.

test(Pred, Var, Result) :-
	call(Pred, Var, Result).

test(Pred, Var) :-
	writeln(before),
	call(Pred, Var),
	writeln(after).


test :-
	test(mult, 2, Z),
	writeln(Z),
	test(not, false),
	test(not, true).
The output is :
6 ?- test.
4
before
after
before
false.

Is-it what you want ?

 
It wotrks like a charm!

Thank you for your quick and accurate reply joel76!

Patrick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top