Serialising Selected Logtalk objects

Suggestions for new Logtalk features

Moderator: Paulo Moura

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

Serialising Selected Logtalk objects

Post by Stefano Bromuri » Sat Jun 25, 2011 5:50 am

Hello Paolo,

one interesting feature you may add to Logtalk is the possibility to add serialisation like you would have in Java. It would be interesting to have Logtalk objects moving around between Prolog engines as mobile agents.

Stefano.

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

Re: Serialising Selected Logtalk objects

Post by Paulo Moura » Sat Jun 25, 2011 12:16 pm

That idea crossed my mind a few times, although I never found an application where such functionality was required. Assuming that only dynamic objects would be serializable, one possible solution would be simply dump all object clauses and respective runtime table entries to a file (or, more generally, a stream). Would that be enough for your case?
Paulo Moura
Logtalk developer

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

Re: Serialising Selected Logtalk objects

Post by Stefano Bromuri » Mon Jun 27, 2011 8:53 am

Thank you for answering Paulo:

I work on Multi-agent systems, and in MAS applications, we have a lot of distributed computation in the field. Having agents that are able to move from one platform to another is not strictly necessary, but it helps a lot. In particular it helps with distributed simulations, as otherwise you have to have complex interaction protocols in place, which, in my experience, is not always desirable.

If I understood correctly, you would dump it to a stream of bytes, correctly?

In the case, what would happen if we have, let's say, a SWI-Prolog running on a Linux machine and a SWI-Prolog running on Windows Machine? Would the Window machine recognize the stream or there would be the canonical little endian/big endian problem?

This is just an extreme case though, if you are able to dump everything in a stream, pass it between Prolog engines, deserialize it to an object and execute the code, even if the Prolog engines have to run on the same operating system, I think it would be enough to start doing some very interesting stuff.

Stefano.

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

Re: Serialising Selected Logtalk objects

Post by Paulo Moura » Mon Jun 27, 2011 9:50 am

Stefano Bromuri wrote: I work on Multi-agent systems, and in MAS applications, we have a lot of distributed computation in the field. Having agents that are able to move from one platform to another is not strictly necessary, but it helps a lot. In particular it helps with distributed simulations, as otherwise you have to have complex interaction protocols in place, which, in my experience, is not always desirable.

If I understood correctly, you would dump it to a stream of bytes, correctly?
No. It would be a dump of the object clauses.
Stefano Bromuri wrote: In the case, what would happen if we have, let's say, a SWI-Prolog running on a Linux machine and a SWI-Prolog running on Windows Machine? Would the Window machine recognize the stream or there would be the canonical little endian/big endian problem?
There is not byte representation to begin with. Only a plain Prolog representation (which is not fully portable across Prolog compilers and operating-systems due to lack of Prolog standardization). The closest thing would be to use e.g. SWI-Prolog QLF streams/files. But that would constrain you to a single Prolog compiler (and note that the QLF format usually changes whenever the SWI-Prolog virtual machine changes between versions).
Stefano Bromuri wrote: This is just an extreme case though, if you are able to dump everything in a stream, pass it between Prolog engines, deserialize it to an object and execute the code, even if the Prolog engines have to run on the same operating system, I think it would be enough to start doing some very interesting stuff.
The problem is not one of being an extreme case but simply that this is not the way Logtalk or Prolog compilers work. Prolog is not Java (and Logtalk is not Java in Prolog). There is no standard virtual machine (some Prolog compilers don't even use a virtual machine). There is no portable way (across Prolog compilers) of dumping any kind of byte code representation that you could pass around.
Paulo Moura
Logtalk developer

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

Re: Serialising Selected Logtalk objects

Post by Stefano Bromuri » Mon Jun 27, 2011 10:58 am

Understood.

Let's restrict: on one Prolog Engine, on one Operating System, distributed settings. Still fine for me, if this is possible.
For example, my choice would be SWI-Prolog.

Regards,

Stefano.

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

Re: Serialising Selected Logtalk objects

Post by Paulo Moura » Mon Jun 27, 2011 3:55 pm

Stefano Bromuri wrote: Let's restrict: on one Prolog Engine, on one Operating System, distributed settings. Still fine for me, if this is possible.
For example, my choice would be SWI-Prolog.
See the SWI-Prolog documentation on the QLF format to check if it would allow the kind of functionality you require. In particular, check the option stream/1 for the load_files/2 predicate. From the Logtalk side, the supporting functionality would likely be restricted to a solution to dump an object clauses to the current output stream and maybe load the result. Loading the "serialized" from of an object could also be accomplished by simply using a Prolog consult predicate.
Paulo Moura
Logtalk developer

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

Re: Serialising Selected Logtalk objects

Post by Stefano Bromuri » Fri Jul 08, 2011 5:02 pm

I am afraid SWI is not this advanced. Is there any other Prolog that Logtalk supports, that would allow to do this?

Stefano.

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

Re: Serialising Selected Logtalk objects

Post by Paulo Moura » Fri Jul 08, 2011 6:21 pm

Stefano Bromuri wrote:I am afraid SWI is not this advanced. Is there any other Prolog that Logtalk supports, that would allow to do this?
I don't think so. An alternative could be to use the same parametric objects on both sides and simply exchange a term with the instantiations of the object parameters. Check the "proxies" example.
Paulo Moura
Logtalk developer

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest