swi-prolog non-dynamic predicates in thread local

This is a discussion on swi-prolog non-dynamic predicates in thread local within the PROLOG forums in Programming Languages category; I use prolog as logic engine in my C++ application with MT. I put my dynamic predicates in thread local storage and it works with 'thread_local' property. Now I want to have different sets of non- dynamic predicates ( sometimes even different implementations of the same predicates) in different running threads of prolog engine. Is there any way to do this? Documentation sais that thread_local are implicitly dynamic predicates. Unless I misunderstood it... Is there any property that would make static predicates thread_local? I figured out that I might use modules to workaround this situation. In this case I'd have ...

Go Back   Application Development Forum > Programming Languages > PROLOG

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-01-2008, 05:03 AM
pmitka
Guest
 
Default swi-prolog non-dynamic predicates in thread local

I use prolog as logic engine in my C++ application with MT.
I put my dynamic predicates in thread local storage and it works with
'thread_local' property. Now I want to have different sets of non-
dynamic predicates ( sometimes even different implementations of the
same predicates) in different running threads of prolog engine. Is
there any way to do this?

Documentation sais that thread_local are implicitly dynamic
predicates. Unless I misunderstood it...

Is there any property that would make static predicates thread_local?

I figured out that I might use modules to workaround this situation.
In this case I'd have separate module for each thread and import each
predicate I want to this module. Is this correct approach? Although
I'd prefer something cleaner/more simplistic...
Reply With Quote
  #2  
Old 08-01-2008, 05:49 AM
Jan Wielemaker
Guest
 
Default Re: swi-prolog non-dynamic predicates in thread local

On 2008-08-01, pmitka <pmitka@gmail.com> wrote:
> I use prolog as logic engine in my C++ application with MT.
> I put my dynamic predicates in thread local storage and it works with
> 'thread_local' property. Now I want to have different sets of non-
> dynamic predicates ( sometimes even different implementations of the
> same predicates) in different running threads of prolog engine. Is
> there any way to do this?
>
> Documentation sais that thread_local are implicitly dynamic
> predicates. Unless I misunderstood it...


Yip, and it cannot be static: new threads start without clauses for
the thread local predicates and and the end of the thread all clauses
are deleted.

> Is there any property that would make static predicates thread_local?


No. I guess in theory this would be possible.

> I figured out that I might use modules to workaround this situation.
> In this case I'd have separate module for each thread and import each
> predicate I want to this module. Is this correct approach? Although
> I'd prefer something cleaner/more simplistic...


That is the right approach. You put all the shared stuff in one or
more modules. For each different context you load all the specific
stuff into a dedicated module and you import the shared modules. Its
not that hard :-)

Cheers --- Jan
Reply With Quote
  #3  
Old 09-11-2008, 06:00 AM
Pawel Mitka
Guest
 
Default Re: swi-prolog non-dynamic predicates in thread local

On 1 Sie, 11:49, Jan Wielemaker <j...@nospam.ct.xs4all.nl> wrote:
> On 2008-08-01,pmitka<pmi...@gmail.com> wrote:
>
> > I useprologas logic engine in my C++ application with MT.
> > I put my dynamic predicates in thread local storage and it works with
> > 'thread_local' property. Now I want to have different sets of non-
> > dynamic predicates ( sometimes even different implementations of the
> > same predicates) in different running threads ofprologengine. Is
> > there any way to do this?

>
> > Documentation sais that thread_local are implicitly dynamic
> > predicates. Unless I misunderstood it...

>
> Yip, and it cannot be static: new threads start without clauses for
> the thread local predicates and and the end of the thread all clauses
> are deleted.
>
> > Is there any property that would make static predicates thread_local?

>
> No. *I guess in theory this would be possible.
>
> > I figured out that I might use modules to workaround this situation.
> > In this case I'd have separate module for each thread and import each
> > predicate I want to this module. Is this correct approach? Although
> > I'd prefer something cleaner/more simplistic...

>
> That is the right approach. *You put all the shared stuff in one or
> more modules. *For each different context you load all the specific
> stuff into a dedicated module and you import the shared modules. *Its
> not that hard :-)
>
> * * * * Cheers --- Jan


Let's assume this situation I really can't find solution:
1. a.pl is a shared module:

:-module(a,[]).
:-export(tst).

tst:-
foo.

2. b.pl is:
:-module(b,[]).

:-export(foo).

foo:-
fail.

It works if I consult both files and import 'a:tst' and 'b:foo' let's
say to dynamic module 'aa' and call aa:tst. (result is fail)
But when I'd like to have module 'bb' with shared predicate imported
from 'a:tst' redefined foo predicate from file c.pl:
3. c.pl is:
:-module(c,[]).

:-export(foo).

foo:-
true.

I consult c.pl and get error:
ERROR: Cannot import c:bob/0 into module user: already imported from b


When I tried to consult that files directly to module 'aa' or 'bb' I
have an error:
a:tst/0: Undefined procedure: a:foo/0
ERROR: However, there are definitions for:
ERROR: aa:foo/0
ERROR: b:foo/0

How do I have to modify my code to make it work? Because certainly I
don't know how to write call for 'foo' predicate in 'a' module to make
it redifinable and how to load module files?
By use_module, consult, import?
Reply With Quote
  #4  
Old 09-11-2008, 07:45 AM
Jan Wielemaker
Guest
 
Default Re: swi-prolog non-dynamic predicates in thread local

On 2008-09-11, Pawel Mitka <pmitka@gmail.com> wrote:
> On 1 Sie, 11:49, Jan Wielemaker <j...@nospam.ct.xs4all.nl> wrote:
>> On 2008-08-01,pmitka<pmi...@gmail.com> wrote:
>>
>> > I useprologas logic engine in my C++ application with MT.
>> > I put my dynamic predicates in thread local storage and it works with
>> > 'thread_local' property. Now I want to have different sets of non-
>> > dynamic predicates ( sometimes even different implementations of the
>> > same predicates) in different running threads ofprologengine. Is
>> > there any way to do this?

>>
>> > Documentation sais that thread_local are implicitly dynamic
>> > predicates. Unless I misunderstood it...

>>
>> Yip, and it cannot be static: new threads start without clauses for
>> the thread local predicates and and the end of the thread all clauses
>> are deleted.
>>
>> > Is there any property that would make static predicates thread_local?

>>
>> No. *I guess in theory this would be possible.
>>
>> > I figured out that I might use modules to workaround this situation.
>> > In this case I'd have separate module for each thread and import each
>> > predicate I want to this module. Is this correct approach? Although
>> > I'd prefer something cleaner/more simplistic...

>>
>> That is the right approach. *You put all the shared stuff in one or
>> more modules. *For each different context you load all the specific
>> stuff into a dedicated module and you import the shared modules. *Its
>> not that hard :-)
>>
>> * * * * Cheers --- Jan

>
> Let's assume this situation I really can't find solution:
> 1. a.pl is a shared module:
>
>:-module(a,[]).
>:-export(tst).
>
> tst:-
> foo.



The normal declaration is as below. export is for some special cases.

:- module(a, [tst/0]).

tst :-
foo.

> 2. b.pl is:
>:-module(b,[]).
>
>:-export(foo).
>
> foo:-
> fail.
>
> It works if I consult both files and import 'a:tst' and 'b:foo' let's
> say to dynamic module 'aa' and call aa:tst. (result is fail)
> But when I'd like to have module 'bb' with shared predicate imported
> from 'a:tst' redefined foo predicate from file c.pl:
> 3. c.pl is:
>:-module(c,[]).
>
>:-export(foo).
>
> foo:-
> true.
>
> I consult c.pl and get error:
> ERROR: Cannot import c:bob/0 into module user: already imported from b
>
>
> When I tried to consult that files directly to module 'aa' or 'bb' I
> have an error:
> a:tst/0: Undefined procedure: a:foo/0
> ERROR: However, there are definitions for:
> ERROR: aa:foo/0
> ERROR: b:foo/0
>
> How do I have to modify my code to make it work? Because certainly I
> don't know how to write call for 'foo' predicate in 'a' module to make
> it redifinable and how to load module files?
> By use_module, consult, import?


Hmm. The problem is (if I understand you correcly; I'm not 100% sure
about that) you want to create two different combinations in the user
module. That of course won't work.

This kind of unification of modules where the unified modules call
each other in different combinations is not that simple. It is more
the domain of OO skins like Logtalk.

I once wrote a very simple-minded mini OO system by tricking the
module system. You can find it here:

http://gollem.science.uva.nl/git/tri...b74016223ff4dd

If you download the project, you can see how it is used.

--- Jan
Reply With Quote
  #5  
Old 09-11-2008, 07:59 AM
Pawel Mitka
Guest
 
Default Re: swi-prolog non-dynamic predicates in thread local

On 11 Wrz, 13:45, Jan Wielemaker <j...@nospam.ct.xs4all.nl> wrote:
> On 2008-09-11, Pawel Mitka <pmi...@gmail.com> wrote:
>
>
>
>
>
> > On 1 Sie, 11:49, Jan Wielemaker <j...@nospam.ct.xs4all.nl> wrote:
> >> On 2008-08-01,pmitka<pmi...@gmail.com> wrote:

>
> >> > I useprologas logic engine in my C++ application with MT.
> >> > I put my dynamic predicates in thread local storage and it works with
> >> > 'thread_local' property. Now I want to have different sets of non-
> >> > dynamic predicates ( sometimes even different implementations of the
> >> > same predicates) in different running threads ofprologengine. Is
> >> > there any way to do this?

>
> >> > Documentation sais that thread_local are implicitly dynamic
> >> > predicates. Unless I misunderstood it...

>
> >> Yip, and it cannot be static: new threads start without clauses for
> >> the thread local predicates and and the end of the thread all clauses
> >> are deleted.

>
> >> > Is there any property that would make static predicates thread_local?

>
> >> No. *I guess in theory this would be possible.

>
> >> > I figured out that I might use modules to workaround this situation.
> >> > In this case I'd have separate module for each thread and import each
> >> > predicate I want to this module. Is this correct approach? Although
> >> > I'd prefer something cleaner/more simplistic...

>
> >> That is the right approach. *You put all the shared stuff in one or
> >> more modules. *For each different context you load all the specific
> >> stuff into a dedicated module and you import the shared modules. *Its
> >> not that hard :-)

>
> >> * * * * Cheers --- Jan

>
> > Let's assume this situation I really can't find solution:
> > 1. a.pl is a shared module:

>
> >:-module(a,[]).
> >:-export(tst).

>
> > tst:-
> > *foo.

>
> The normal declaration is as below. *export is for some special cases.
>
> :- module(a, [tst/0]).
>
> tst :-
> * * foo.
>
>

I used this way but in some tests I've changed to exports...

>
>
>
> > 2. b.pl is:
> >:-module(b,[]).

>
> >:-export(foo).

>
> > foo:-
> > * *fail.

>
> > It works if I consult both files and import 'a:tst' and 'b:foo' let's
> > say to dynamic module 'aa' and call aa:tst. (result is fail)
> > But when I'd like to have module 'bb' with shared predicate imported
> > from 'a:tst' redefined foo predicate from file c.pl:
> > 3. c.pl is:
> >:-module(c,[]).

>
> >:-export(foo).

>
> > foo:-
> > * *true.

>
> > I consult c.pl and get error:
> > ERROR: Cannot import c:bob/0 into module user: already imported from b

>
> > When I tried to consult that files directly to module 'aa' or 'bb' I
> > have an error:
> > a:tst/0: Undefined procedure: a:foo/0
> > ERROR: * * However, there are definitions for:
> > ERROR: * * * * aa:foo/0
> > ERROR: * * * * b:foo/0

>
> > How do I have to modify my code to make it work? Because certainly I
> > don't know how to write call for 'foo' predicate in 'a' module to make
> > it redifinable and how to load module files?
> > By use_module, consult, import?

>
> Hmm. *The problem is (if I understand you correcly; I'm not 100% sure
> about that) you want to create two different combinations in the user
> module. *That of course won't work.
>


I don't wan't to load it all to user module if it's possible. I wan't
ot have 2 separate modules where I'd have 2 separate definitions of
the same predicate 'foo' used by predicate 'tst' in separate dynamic
modules:
1. a.pl + b.pl
2. a.pl + c.pl

I wasn't able to find way to make it work correctly.

> This kind of unification of modules where the unified modules call
> each other in different combinations is not that simple. *It is more
> the domain of OO skins like Logtalk.
>
> I once wrote a very simple-minded mini OO system by tricking the
> module system. *You can find it here:
>
> http://gollem.science.uva.nl/git/tri...src/particle.p....
>
> If you download the project, you can see how it is used.
>
> * * * * --- Jan- Ukryj cytowany tekst -
>
> - Pokaż cytowany tekst -- Ukryj cytowany tekst -
>
> - Pokaż cytowany tekst -


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 04:18 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.