Re: Interactive programming with pengines
Torbjörn Lager <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CA+Y3JZhe_WqPgL71jDYn6=3phaLdy4uYF-4xN842k0ayf0m=Yg@mail.gmail.com> |
On Sun, Feb 9, 2014 at 5:45 PM, Jan Wielemaker <[email protected]> wrote: > Having something like that seems great for understanding pengine > interaction. The downside is that except for learning to play with them, > I see no use for this. Right? If right, I'm a bit reluctant to add > complications to the code only for demo and playing purposes. Well, how about for demo, playing and _testing_ purposes? Suppose a developer isn't sure if a particular pengine server does what is supposed to do. She can do: ?- pengine_create([name(a), server('http://pengines.org/')]). ... and then try out things interactively to her hearts content! And if you CAN do interactive programming in a way that you can later rather easily put together into a full program, then isn't that is a sign of quality and maybe even beauty? (Or am I overstretching myself here?) I think that IF we leave this interactivity out (if only I happen to like it), I myself will write a pengine_utils.pl that will give me this functionality. It felt good being able to program like that, and if it felt good for me I guess it could feel good for others. But it could start as a utils library, and if used a lot, then this feature could be made part of pengines.pl. > After all, the idea behind pengines is the same as behind Paul Tarau's > engines: have a _machine_ interact with Prolog engines. (except that > Paul's engines are local and aiming at Prolog only interaction where > yours are either local or remote and aim also at interacting with other > languages). We already have the toplevel for interacting with users. Yes, but this would be for user interacting also with pengines, sometimes running concurrently, sometimes running remotely. Seems to me that it makes a difference. > Wouldn't it make more sense to write a web application that allows for > playing with the pengine protocol? That opens the playground for people > that may be less experienced using Prolog. Yes, we could do that too, but it's a lot more work. :-( > Cheers --- Jan > > P.s. At some point I'd like to launch pengines.swi-prolog.org to > run a public demo. The stuff you created is one. This would > make another nice demo. Looking forward! Cheers, Torbjörn > On 02/09/2014 05:00 PM, Torbjörn Lager wrote: >> One thing I like about Prolog is that most things can be explored >> interactively, at the ?- prompt. It's a good way to explore a new >> library for example. Having the name(<name>) option in >> pengine_create/1 is one way of making this more convenient. Already at >> this point, we can do: >> >> ?- pengine_create([name(a)]). >> true. >> >> ?- pengine_create([name(b)]). >> true. >> >> ?- pengine_ask(a, member(A, [a,b,c])). >> true. >> >> ?- pengine_ask(b, append(Xs, Ys, [a,b,c]), [template(Xs-Ys)]). >> true. >> >> ?- pengine_next(b). >> true. >> >> ?- pengine_next(a). >> true. >> >> ?- pengine_event_loop(writeln). >> create(eddcb314-9192-11e3-a036-3c075453f481,true) >> create(f1d773aa-9192-11e3-b8e0-3c075453f481,true) >> success(eddcb314-9192-11e3-a036-3c075453f481,[member(a,[a,b,c])],true) >> success(f1d773aa-9192-11e3-b8e0-3c075453f481,[[]-[a,b,c]],true) >> success(f1d773aa-9192-11e3-b8e0-3c075453f481,[[a]-[b,c]],true) >> success(eddcb314-9192-11e3-a036-3c075453f481,[member(b,[a,b,c])],true) >> >> >> The problem is that you don't get any responses until you call >> pengine_event_loop/1, and then you'll get all of them at the same >> time. Also, once you have called pengine_event_loop/1, you won't be >> able to send more commands to your pengines. :-( >> >> Fortunately, I think this can be fixed by adding an option >> 'asynch(Boolean)' to pengine_event_loop/1. (Boolean should most likely >> be false by default, since using asynch(true) uses an extra thread.) >> Now, we would be able to START the interaction by starting the event >> loop: >> >> ?- pengine_event_loop(writeln, [asynch(true)]). >> true. >> >> ?- pengine_create([name(a)]). >> create(eddcb314-9192-11e3-a036-3c075453f481,true) >> true. >> >> ?- pengine_create([name(b)]). >> create(f1d773aa-9192-11e3-b8e0-3c075453f481,true) >> true. >> >> ?- pengine_ask(a, member(A, [a,b,c])). >> success(eddcb314-9192-11e3-a036-3c075453f481,[member(a,[a,b,c])],true) >> true. >> >> ?- pengine_ask(b, append(Xs, Ys, [a,b,c]), [template(Xs-Ys)]). >> success(f1d773aa-9192-11e3-b8e0-3c075453f481,[[]-[a,b,c]],true) >> true. >> >> ?- pengine_next(b). >> success(f1d773aa-9192-11e3-b8e0-3c075453f481,[[a]-[b,c]],true) >> true. >> >> ?- pengine_next(a). >> success(eddcb314-9192-11e3-a036-3c075453f481,[member(b,[a,b,c])],true) >> true. >> >> ?- >> >> Instead of using writeln/1 as the handler, we could probably use a >> predicate (maybe pengine_write_event/1) that replaced IDs with names, >> like so: >> >> ?- pengine_event_loop(pengine_write_event, [asynch(true)]). >> true. >> >> ?- pengine_create([name(a)]). >> create(a,true) >> true. >> >> ?- pengine_create([name(b)]). >> create(b,true) >> true. >> >> ?- pengine_ask(a, member(A, [a,b,c])). >> success(a,[member(a,[a,b,c])],true) >> true. >> >> ?- pengine_ask(b, append(Xs, Ys, [a,b,c]), [template(Xs-Ys)]). >> success(b,[[]-[a,b,c]],true) >> true. >> >> ?- pengine_next(b). >> success(b,[[a]-[b,c]],true) >> true. >> >> ?- pengine_next(a). >> success(a,[member(b,[a,b,c])],true) >> true. >> >> ?- pengine_create([name(c)]). >> create(c,true) >> true. >> >> ?- pengine_ask(c, (between(1, 3, X), pengine_output(X), fail). >> output(c,1) >> output(c,2) >> output(c,3) >> success(c,[(between(1, 3, X), pengine_output(X), fail)],true) >> true. >> >> Adding the asynch option to pengine_create/1 might be a good idea. Thoughts? >> >> - Torbjörn >> -- Torbjörn Lager Professor of General and Computational Linguistics Department of Philosophy, Linguistics and Theory of Science University of Gothenburg Box 200, SE-405 30 Gothenburg, Sweden Phone: +46317864962