Serializing Logtalk Objects ?

Help requests on developing Logtalk applications

Moderator: Paulo Moura

Post Reply
Stefano Bromuri
Posts: 8
Joined: Wed Nov 05, 2008 3:09 pm

Serializing Logtalk Objects ?

Post by Stefano Bromuri » Wed Nov 19, 2008 4:30 pm

Hello guys,

I am aware that I've always weird questions :), but I was thinking that maybe some of you has tried to serialize a set of logtalk objects.
Do you have any clue on how to do this ?

Basically what I need is a way to save in a file (or a string) the PROLOG context, in order to be able to store it and reload it/send it over the network and every weird thing you can imagine.

Of course at runtime.....dynamic state included... :).

My setting is: swi-prolog + interprolog + logtalk.

Best Regards,

Stefano.

Paulo Moura
Logtalk developer
Posts: 474
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Serializing Logtalk Objects ?

Post by Paulo Moura » Wed Nov 19, 2008 5:07 pm

Stefano Bromuri wrote: I am aware that I've always weird questions :), but I was thinking that maybe some of you has tried to serialize a set of logtalk objects. Do you have any clue on how to do this ?
Depends on the complexity of the Logtalk objects that you want to serialize. For simple, dynamic objects one solution is to write to a file the Logtalk source code corresponding to the objects. In this case, restoring the serialized objects would be just a question of compiling and loading the generated source files. But see below for a possible alternative.
Stefano Bromuri wrote: Basically what I need is a way to save in a file (or a string) the PROLOG context, in order to be able to store it and reload it/send it over the network and every weird thing you can imagine.

Of course at runtime.....dynamic state included... :).

My setting is: swi-prolog + interprolog + logtalk.
Take a look to the documentation on saved states and the qsave_program/2 built-in predicate SWI-Prolog.

Cheers,

Paulo
Paulo Moura
Logtalk developer

Stefano Bromuri
Posts: 8
Joined: Wed Nov 05, 2008 3:09 pm

Re: Serializing Logtalk Objects ?

Post by Stefano Bromuri » Wed Nov 19, 2008 5:29 pm

Paulo Moura wrote:
Stefano Bromuri wrote: I am aware that I've always weird questions :), but I was thinking that maybe some of you has tried to serialize a set of logtalk objects. Do you have any clue on how to do this ?
Depends on the complexity of the Logtalk objects that you want to serialize. For simple, dynamic objects one solution is to write to a file the Logtalk source code corresponding to the objects. In this case, restoring the serialized objects would be just a question of compiling and loading the generated source files. But see below for a possible alternative.
Stefano Bromuri wrote: Basically what I need is a way to save in a file (or a string) the PROLOG context, in order to be able to store it and reload it/send it over the network and every weird thing you can imagine.

Of course at runtime.....dynamic state included... :).

My setting is: swi-prolog + interprolog + logtalk.
Take a look to the documentation on saved states and the qsave_program/2 built-in predicate SWI-Prolog.

Cheers,

Paulo
I am having a look at qsave_program indeed. What I don't get is how to reload the archive from the prolog context. I had success in saving the state with the emulator, although it is not what I need exactly...

Thank you for your help, please if you solve the issue before me let me know, I'll do the same...

Paulo Moura
Logtalk developer
Posts: 474
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Serializing Logtalk Objects ?

Post by Paulo Moura » Wed Nov 19, 2008 5:40 pm

Stefano Bromuri wrote: I am having a look at qsave_program indeed. What I don't get is how to reload the archive from the prolog context. I had success in saving the state with the emulator, although it is not what I need exactly...

Thank you for your help, please if you solve the issue before me let me know, I'll do the same...
As an example, try:

Code: Select all

% swilgt
...
?- {aliases(loader)}.

?- square(2)::side(Side).
Side = 2.

?- qsave_program(myprog, [stand_alone(false)]).
% /opt/local/lib/swipl-5.7.2/library/ctypes compiled into ctypes 0.00 sec, 5,196 bytes
% /opt/local/lib/swipl-5.7.2/library/backcomp compiled into backward_compatibility 0.00 sec, 7,752 bytes
% /opt/local/lib/swipl-5.7.2/library/apply compiled into apply 0.00 sec, 3,676 bytes
% /opt/local/lib/swipl-5.7.2/library/terms compiled into terms 0.00 sec, 1,140 bytes
% /opt/local/lib/swipl-5.7.2/library/date compiled into date 0.00 sec, 9,564 bytes
% /opt/local/lib/swipl-5.7.2/library/gensym compiled into gensym 0.00 sec, 2,500 bytes
% /opt/local/lib/swipl-5.7.2/library/listing compiled into prolog_listing 0.01 sec, 19,440 bytes
true.

?- halt.

% ./myprog
...
?- square(2)::side(Side).
Side = 2.
Hope this helps (I never used saved states before but I'm sure others in the SWI-Prolog mailing list will be able to provide you with further assistance).

Cheers,

Paulo
Paulo Moura
Logtalk developer

Stefano Bromuri
Posts: 8
Joined: Wed Nov 05, 2008 3:09 pm

Re: Serializing Logtalk Objects ?

Post by Stefano Bromuri » Wed Nov 19, 2008 9:01 pm

Hi Paolo, I did try qsave_program/2 with interprolog as well:

With interprolog then the command to call is not the standrd "pl" as usual, the command to call is the executable file generated with qsave_program.

Basically it is straightforward now to take the file generated with qsave_program, send it to another host and perform some computation.

I am very happy with this result, thank you for the help !

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest