-
It is possible in Scryer Prolog to pass a list of predicate names to a predicate defined in a module and have that predicate evaluate the predicates whose names are passed to it? Here is a short example to demonstrate what I'm trying to do. % This is the contents of my_module.pl.
:- module(my_module, [call_predicates/1]).
:- use_module(library(lists)).
call_predicate(P) :-
Goal =.. [P],
call(Goal).
call_predicates(Ps) :- maplist(call_predicate, Ps). % This is the contents of main.pl.
:- use_module(my_module).
first :- write('in first'), nl.
second :- write('in second'), nl.
demo :- call_predicates([first, second]). When I load |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 17 replies
-
The module system is predicate based. That means that predicates are grouped into modules, but functors, atoms are not. So For many uses, it suffices to declare with a These In your case, you want a list of goals. That is not directly supported. So you need to first convert terms to such goals. You might do this explicitly (don't!) or
(for each N). Do not, repeat, do not rely on the internal representation using For most uses, this leads to a quite consistent system. But these meta-arguments are effectively used as input arguments only. However, once you want to use another mode like analyze such arguments directly, things get very messy. In case of doubt, refer there to SICStus and not SWI since SWI was originally based on a different predicate based module system and only later adapted SICStus style while still maintaining backwards compatibility which lead to differences that show in such cases. Just another remark on |
Beta Was this translation helpful? Give feedback.
-
The following paper may be useful: @incollection {pmoura12d,
author = "Paulo Moura",
title = "{Meta-predicate Semantics}",
booktitle = {Logic-Based Program Synthesis and Transformation},
series = {Lecture Notes in Computer Science},
editor = "Germán Vidal",
publisher = {Springer Berlin / Heidelberg},
isbn = {978-3-642-32210-5},
keyword = {Computer Science},
pages = {155-172},
volume = {7225},
url = {http://dx.doi.org/10.1007/978-3-642-32211-2_11},
doi = {10.1007/978-3-642-32211-2_11},
year = {2012}
} Mail me @ logtalk.org if you want a copy. |
Beta Was this translation helpful? Give feedback.
-
I have a programming example in Logtalk doing just that (passing a list of predicates to be called in their definition context) at: https://github.com/LogtalkDotOrg/logtalk3/blob/master/examples/metapredicates/goals.lgt But it uses Logtalk objects instead of Prolog modules. Still, you may find it useful. You can run the example with Scryer Prolog:
P.S. You can also run this example with B-Prolog, Ciao Prolog, CxProlog, ECLiPSe, GNU Prolog, JIProlog, LVM, Quintus Prolog, SICStus Prolog, SWI-Prolog, Tau Prolog, Trealla Prolog, XSB, and YAP. |
Beta Was this translation helpful? Give feedback.
@UWN Here is my latest version of the code I shared previously. See the questions in the TODO comments. Besides those questions, I'm interested in learning what else you would do differently in this code or what naming changes you recommend.