Thanks @Boris and @Jan. I didn’t think about going at it from a “transform the top level program” point of view, I was more thinking about ways to match and transform the innermost predicate (i.e. testz/1
). Good idea, I think that might work for my scenario. I’ll have to think about it more.
@Boris, I avoided throwing in the whole scenario because it seemed really specific to my implementation, but here goes in case you’re interested:
My program in an interactive fiction engine that allows you to modify state using a planning approach known as Hierarchical Task Networks (HTNs). Currently, you define a “task” (to accomplish part of a plan) using a special predicate that has Prolog commands as part of the “condition” where the task is appropriate. Here is an example that implements “reading something that is text” (as apposed to reading something which is a book, for example):
% if Object *is* text, just read it
readObject(_, Object, Context) :- htnMethod([], Context,
if([
inReach(Object),
instanceOf(Object, idText),
getText(Object, _, Text)
]),
do([opMessage(readTextOnly, Text)]) ).
You’ll see that the Prolog commands are all part of a list which get executed by the engine manually using call/1. This is why I was asking this question, I couldn’t figure out a way to transform terms that were part of a list like that.
To tie this together with the other question I asked, what I’d really like to have is something like this:
% if Object *is* text, just read it
readObject(_, Object, Context) :- htnMethod([], Context,
if([
inReach(Object),
instanceOf(Object, idText),
getText(Object, _, Text)
]),
do([sayToUser("it says [Text]")]) ).
and have the string "it says [Text]"
be transformed by the templating engine I describe in the other post.