I have a project where I’m serialising all my predicates and modules (AKA performing source dumps) but I realised that I can’t seem to serialise PCE Classes. Usually if I want to dump source of a module I do listing(Module:_) with output redirected to a stream. However, I can’t do this with defined PCE classes since I suppose PCE classes don’t end up as Prolog predicates. Since I haven’t got a workaround for this right now I can’t use PCE classes, which is an annoying problem because it means I can’t really do arbitrary state on objects. I have mostly been able to work around this but I’d really rather not! Any ideas?
I have no idea why you want this. But, there are built-in classes in xpce that you cannot access and Prolog defined classes. Prolog translates the :- pce_begin_class(...)
, etc into Prolog facts. The generation of the actual xpce class is done lazily when the class is referenced. Similarly, methods are added lazily. So, the serialization of an xpce class is basically the serialization of these Prolog facts. See xpce/prolog/boot/pce_expansion.pl for the translation and pce_realise.pl there (if I recall correctly) for the lazy binding.
Normal serialization of the Prolog state using qsave_program/2 deals with xpce classes this way (and is the reason for this design).
The reason is because I want to serialise it into readable source format AKA I want to retain as much of the original code as possible, but with all the extra dynamic predicates that I define at runtime. E.G., if I’m creating a time planner, I want to be able to dump my source with all of the extra predicates I’ve defined at runtime. I suppose I could try and retain a list of transactions, then use the original source + execute those transactions on top + use qsave as needed, but I’m not sure if that is any better. But readability is the primary reason for me not to use qsave only. Currently I’m trying to retain as much of the original code’s structure as possible, modules and whatnot included, for that purpose.
It does save them as prolog facts? I see. However it doesn’t seem to save them as facts within the module I defined the class in, which interferes with the results of listing
. I’ll look into pce_realise and pce_expansion to see if I can figure out where those facts have been saved to