Asserting facts into the caller's module

I have a module that processes dicts and assertz facts from them. I’d like the facts to end up in the caller’s module, but despite tinkering with export, module_transparent and so on I haven’t been able to get it to work. I know the facts are there because I can access them if I prefix them with the module that generates them, and if I explicitly specify the calling module to assertz they end up in there, but I don’t want to have to hard-code it.

Thanks!

You should be able to use meta_predicate/1 to indicate the predicate’s arguments should be module-qualified, then get the module from there? e.g. something like

:- meta_predicate foo(:).

foo(Module:Stuff) :-
   do_stuff(Stuff, Fact),
  assertz(Module:Fact).
2 Likes

That looks like it does the trick, thanks!

1 Like