Re: Dataflow variables
Alan Baljeu <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Except that the implementation is single-threaded, CHR is perfect for this kind of thing. :- chr_constraint some_delayed_computation/2. some_delayed_computation(X, Y) ==> ground(X) | code to compute Y here. Or with a little rethinking, you can name the predicates for your dataflow variables, and do: :- chr_constraint thing/1, other_thing/1. thing(A) ==> B is A*2, other_thing(B). With this, whenever a thing/1 is made, it runs whatever computations depend on thing, (or until thing is destroyed). It's very dataflow-like. Alan Baljeu On Sunday, November 3, 2013 12:24:42 PM, Jan Wielemaker <[email protected]> wrote: On 11/03/2013 04:50 PM, Aleksey wrote: > Hi guys > > I'm curious what is the easiest way to imitate dataflow variables in Swi-Prolog > My current idea is something like this (pseudocode): > > wait_for(X) :- > freeze(X, awake_this_thread), > suspend_this_thread. One problem here is that threads share terms nor variables. The only ways to talk to each other is by using shared dynamic predicates or message queues. Some systems (e.g., Ciao) have the ability to suspend on clauses being added to a dynamic predicate. That is easy enough to implement. I guess this would mean we have to revert to the immediate update model for such predicates though. Never studied this facility in enough detail. Sharing variables (and terms) between threads would be interesting, but requires a quite different design. Cheers --- Jan > > test :- > do_work_in_separate_thread(Results), > wait_for(Results), > write(Results). > > I'm also interested if there is a way to make those predicates/functions that > require some of their inputs to be bound to execute to automatically suspend > until corresponding variables are bound, e.g.: > > test :- > bind_X_in_separate_thread_after_long_calculation(X), > Y is X+1, > write(X). > > (here I expect for "Y is X+1" to suspend until X gets bound). > -------------- next part -------------- > HTML attachment scrubbed and removed > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog > _______________________________________________ SWI-Prolog mailing list [email protected] https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog -------------- next part -------------- HTML attachment scrubbed and removed