Hello,
For an API I want to generate (domain specific) predicates dynamically that I want to export.
For example, suppose I have a table of terms, and for each term I want to generate an exported predicates, as so:
gen_table(cond1, arg11).
gen_table(cond2, arg21).
I want to generate something like this:
cond1(X, Y) :-
process(X, cond1, arg11, Y).
cond1(X, Y) :-
process(X, cond2, arg21, Y).
The main idea is to avoid a generic predicate API names with table lookup and instead offer a syntactically domain specifically named predicate for an API.
process(X, Y) :-
gen_table(X, Arg),
process(X, Arg, Y).
The alterantive right now is to write “manually” API predicates for each table entry, which seems useful for the API user but a lot of duplication from the coding point of view.
Can this be done?
Edit:
Modeled on expand_maplist, i tried the following:
https://cplint.eu/pldoc/doc/SWI/library/apply_macros.pl?show=src
init_compile :-
Clause1 = (check_me(X) :- integer(X)),
compile_aux_clauses([Clause1]),
check_me(1).
But, compile_aux_clauses fails.
couldn’t get this to work with compile_aux_clauses
I guess, the simple alternative is to write another program that simply generates a module which i then include in the other program …
thanks,
Dan