Threaded queries? Rulebase independence?

Modules are independent, so you can indeed create multiple worlds. Neither modules nor predicates are subject to garbage collection though. You abolish a predicate, but that will merely unlink its clauses and leave these for being collected by the clause garbage collector. The (not so big) predicate instance itself is never reclaimed. Same applies to a module. You can empty a module, but you cannot destroy the module.

There in_temporary_module/3 which does reclaim (almost) the whole lot. Using temporary modules has some restrictions though, notably not to make any other module dependent on this module and make sure all goals related to the module have finished before the module is being deleted. The temporary module mechanism is what SWISH uses to isolate users and make sure almost all data is reclaimed after a query terminates.

I guess you do not use all these modules at the same time, so you should be able to empty and reuse modules.

You can do this as

?- forall(current_predicate(mod_123:P), abolish(mod_123:P)).

Another, somewhat clumsy, way is to add an additional argument to each predicate that represents the world. With some work you can achieve that using program transformation, so your code remains nice. That can fully and safely reclaim all data as clauses are subject to garbage collection. It may harm clause indexing (and thus performance) though.

I don’t know what Logtalk does at its core when using @pmoura’s suggestions. Eventually, I guess , it should be one of the above. Higher levels of abstraction can never make something possible, it can only make it (sometimes a lot) easier.

2 Likes