# Generating and export predicates: compile\_aux\_clauses(+Clauses)

**URL:** <https://swi-prolog.discourse.group/t/generating-and-export-predicates-compile-aux-clauses-clauses/4907>\
**Category:** Help!\
**Created:** [January 16, 2022, 7:36am UTC](https://swi-prolog.discourse.group/t/generating-and-export-predicates-compile-aux-clauses-clauses/4907 "2022-01-16T07:36:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![grossdan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/grossdan/32/23_2.png) [@grossdan](https://swi-prolog.discourse.group/u/grossdan)\
**Post date:** [January 16, 2022, 7:36am UTC](https://swi-prolog.discourse.group/t/generating-and-export-predicates-compile-aux-clauses-clauses/4907/1 "2022-01-16T07:36:37Z")

</div>

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:

```prolog
gen_table(cond1, arg11).
gen_table(cond2, arg21).

```

I want to generate something like this:

```prolog
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.

```prolog
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/](https://cplint.eu/pldoc/doc/)_SWI_/library/apply\_macros.pl?show=src

```prolog
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

---

<div class="post-metadata">

**Author:** ![kuniaki.mukai](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kuniaki.mukai](https://swi-prolog.discourse.group/u/kuniaki.mukai)\
**Post date:** [January 17, 2022, 4:19am UTC](https://swi-prolog.discourse.group/t/generating-and-export-predicates-compile-aux-clauses-clauses/4907/2 "2022-01-17T04:19:36Z")

</div>

I my case, I wrap compile\_aux\_clauses/1 in ignore/1 since a long time ago (10 years?). I don’t remember the reason why doing so. Anyway no problem has been found so far for my purpose.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [January 17, 2022, 8:25am UTC](https://swi-prolog.discourse.group/t/generating-and-export-predicates-compile-aux-clauses-clauses/4907/3 "2022-01-17T08:25:47Z")

</div>

compile\_aux\_clauses/1 is det, so no need for ignore. Well, I don’t think it does a lot of error checking, so it may fail on illegal input.

---

<div class="post-metadata">

**Author:** ![grossdan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/grossdan/32/23_2.png) [@grossdan](https://swi-prolog.discourse.group/u/grossdan)\
**Post date:** [January 17, 2022, 10:36am UTC](https://swi-prolog.discourse.group/t/generating-and-export-predicates-compile-aux-clauses-clauses/4907/4 "2022-01-17T10:36:25Z")

</div>

How exactly does valid input look like … i tried to glean it from the apply macro code but didn’t succeed …

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [January 17, 2022, 10:51am UTC](https://swi-prolog.discourse.group/t/generating-and-export-predicates-compile-aux-clauses-clauses/4907/5 "2022-01-17T10:51:05Z")

</div>

It is either a valid Prolog source term or a list thereof. It will probably only fail on an invalid list, e.g. `[p|q]`.
