List manipulation problem

From: Eddie Jobson (mirrormaze_at_inwind.it)
Date: 03/25/05


Date: 25 Mar 2005 03:55:35 -0800

In my meta-program I need to replace a clause with a new one who has
the same head but a different body, that is some particular literals
(belonging to a list B) in it have to be replaced with a single
occurrence of a constant string 'secret'.
So I use this procedure:

do( (Head :- Body), B, Output) :-
             makelist(Body,List), %put the body literals in a list
                 setof(
                        X,
                    (
                        member(X, List),
                        functor(X, Functor, Arity),
                        Name = Functor/Arity,
                        member(Name, B)
                        ),
                        ToSecret
                        ), %finds the literals to changed
                  set_difference(List, ToSecret, OutDiff),
                  merge(OutDiff, ['secret'], OutSecret).

It works well, but after obtaining OutSecret I don't know how to
reconstruct the rule (Output). It seems I need a procedure to convert
this list into a single term (a concatenation of each element with ','
as separator), but I can't use built-in string concatenation
predicates because the list can contain variables. Any suggestion?

Thanks in advance.