Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Java Beans <--> Prolog

1 view
Skip to first unread message

rupert...@googlemail.com

unread,
Oct 10, 2008, 6:24:07 AM10/10/08
to
Does anyone know of a library that will let me easily translate
between Java beans and Prolog functors?

For example, if I have:

class MyBean {
public MyBean(String name, int value) { this.name = name; this.value =
value; }
String name;
int value;
}

Then an equivalent as a Prolog functor might be something like:

my_bean(class, name/string, value/int).

And if I have:

MyBean testBean = new MyBean("test", 27).

Then an equivalent as a Prolog functor might be something like:

test_bean(instance/my_bean, name/"test", value/27).

Where one bean contains a reference to another, it might be
represented something like:

bean_a(instance/a, ... fields of a).
bean_b(instance/b, reference/bean_a, ... remaining fields of b).

I want to be able to query Prolog from Java and create a bean from a
variable that gets bound to a Prolog 'bean' in the results. And
conversely I'd like a library functor on the Prolog side, that takes a
bean argument and creates it on the Java heap.

Many thanks for any pointers or suggestions.

Rupert

P L

unread,
Oct 13, 2008, 7:07:53 AM10/13/08
to
JPL is SWI-Prolog's Java interface ... have not used it though

http://www.swi-prolog.org/packages/jpl/


A long long time ago, I had done some Java - Prolog interconnecting using
Amzi!

I assume most popular Prologs, will probably offer some library, to
interface to Java or some other langugage.


? <rupert...@googlemail.com> ?????? ??? ??????
news:ef55d2df-8378-4300...@b1g2000hsg.googlegroups.com...

Paul Singleton

unread,
Oct 13, 2008, 7:56:29 AM10/13/08
to rupert...@googlemail.com
rupert...@googlemail.com wrote:
> Does anyone know of a library that will let me easily translate
> between Java beans and Prolog functors?

I can't see an obviously right, or consensus, mapping from Java beans
to Prolog terms, so unless someone else has already addressed pretty
much the same requirements as yours, I doubt there's a library.

> For example, if I have:
>
> class MyBean {
> public MyBean(String name, int value) { this.name = name; this.value =
> value; }
> String name;
> int value;
> }
>
> Then an equivalent as a Prolog functor might be something like:
>
> my_bean(class, name/string, value/int).

Consider using an established "map" ADT for representing the fields.

> And if I have:
>
> MyBean testBean = new MyBean("test", 27).
>
> Then an equivalent as a Prolog functor might be something like:
>
> test_bean(instance/my_bean, name/"test", value/27).
>
> Where one bean contains a reference to another, it might be
> represented something like:
>
> bean_a(instance/a, ... fields of a).
> bean_b(instance/b, reference/bean_a, ... remaining fields of b).
>
> I want to be able to query Prolog from Java and create a bean from a
> variable that gets bound to a Prolog 'bean' in the results. And
> conversely I'd like a library functor on the Prolog side, that takes a
> bean argument and creates it on the Java heap.

Have a look at the Java Serialization API, e.g.

http://java.sun.com/developer/technicalArticles/Programming/serialization/

SWI-Prolog's JPL lets you query Prolog from Java and explore Java
classes through the Reflection API

> Many thanks for any pointers or suggestions.

> Rupert

cheers - Paul Singleton

0 new messages