Viewing source / setting breakpoints on term_expansion/2 generated rules

If I use term_expansion/2 like this:

term_expansion(createWritelnPredicate(PredicateName),
    [
        (NewPredicateHead :- writeln(TextToWriteln))
    ]) :-
        NewPredicateHead =.. [PredicateName, TextToWriteln]
    .
createWritelnPredicate(test99).

Is there a way to view the generated source for the rule test99 in gxref/0? If I click on that name in that tool, it just takes me to the line:

createWritelnPredicate(test99).

not the generated source.

I’m trying to set a breakpoint inside the generated source. Is there a way to do that?

I won’t call it “generated source”. Source is (IMO) something you wrote. The actual clause is not even in a temporary file. In theory it should be possible to list the generated clause and use that representation to set a breakpoint. That doesn’t exist. In this case I’d simply use ?- spy(test88).

I guess the remark is similar to the other: if you use goal/term expansion to turn a source code into something that lacks a one-to-one mapping between terms in the source code and goals in the final clause(s), you get a poor source level debugging experience. If rewriting merely rewrites goal arguments everything typically keeps working. On more elaborate changes that maintain this one-to-one mapping additional rules can be use to make the debugger work.

Got it, thanks. Yes for this example there are many variables created that aren’t in the original goal so this probably isn’t a great use of the system, at least from a debugging experience perspective.

term_expansion/2 is for facts, rules and directives. Do you assume that
term_expansion/2 is directly called for goals? This post is where I saw the terminology error
for the first time today.

Namely this input here:

is a fact. Its not a goal. You are just expanding a fact via term_expansion/2. If it were a goal you would need to define goal_expansion/2. But you defined term_expansion/2, which is responsible for facts, rules and directives.

Yes, I should have said fact.