Thursday, March 14, 2019

Prolog - The funky functor

From a List to a Function with arguments

I always wondering if I can dynamically call prolog function. It turns out that there is a way to do that. Its form is as follow:

  ?Term =.. ?List
For example, let say that I have the following predicates:
  isa(router, equipment).
  isa(routing_engine, fru).
  isa(fpc, fru).

  partof(routing_engine, router).
I can do:
  Term =.. [isa, router, X], Term, write(X).
This is the equivalent of:
  isa(router,X), write(X).
Which gives us the following printout:
  equipment

#prolog #programming

No comments:

Post a Comment