You can create any kind and amount of code in the most modern Prolog environment using the term extension , with some help the universal operator . The following example works for SWI:
term_expansion(gen_tellme(N), Terms) :- findall((tellme(F) :- tellme(X)), (between(1, N, I), atom_concat(friend, I, Fi), F =.. [Fi, X]), Terms). gen_tellme(25). % generates 25 copies of the tellme clause.
However, embedding information in a predicate name, that is, a friend’s number, is usually not a good design. Why not rewrite the code with friend(N, X) , where N is the number?
source share