Guidance please on where to put certain code when running PEngines?

#1

I’m setting up my app to use with PEngines, which I now have running. I do need a little help on where certain things are supposed to go. A few questions:

  • What if anything should I put in my INI file? Currently, in that file, I switch to the Pengines directory and then consult run.pl. Is that the right place for those items?
  • Where do I put the statements that setup the Pengines application? I’m referring to the pengine_application() and use_module() statements. The INI file? Or should I put that in run.pl?

My main question is how much if any hacking of the code in the run.pl file should I do and if not any, where does that go?

#2

If you only want to run one Prolog application on this computer you can of course put things in your INI file, but typically you use it only to do some personalization of the development tools. Just double click the main .pl file should do to start an application.

I’m not sure you are talking about SWISH or the older Pengines application? For SWISH the normal way to extend and configure is is to create a directory config-enabled and copy standard config files from config-available or add your own. The older Pengines repo is not maintained much.

1 Like
#3

I’m not sure you are talking about SWISH or the older Pengines application? For SWISH the normal way to extend and configure is is to create a directory config-enabled and copy standard config files from config-available or add your own. The older Pengines repo is not maintained much.

Hi Jan,

I’m talking about using Pengines from a Javascript client with the Prolog code for my app already loaded on the server side for the client’s use.

My understanding is that I need the following statements to get my application code loaded into Pengines on the server side, so that the predicates I exposed in my main module are available via requests made from client code. In my case, the client is a Node.JS Javascript app that wants to make calls into my application. Here are the calls I believe are necessary to load that code into PEngines on the server side:

	pengine_application(my_app),
	use_module(my_app:library(main_module))

main_module is my “top level” Prolog source file that contains a module definition for the exported predicates. I don’t know where I should put the two above statements (e.g. - run.pl, INI file, etc.) and if that is everything I need to do to make the predicates exported by main_module available to code that calls into my Pengine instance via the ask() Javascript function:

            var pengine = new Pengine({
                ask: 'q(X)',
                onsuccess: handleSuccess
            });
            function handleSuccess() {
                $('#out').html(this.data[0].X);
                if (!this.more) {
                   $('#next').prop("disabled", true);
                }
            }

So in my case the code for q() would already be loaded into my Pengines instance on the server side at startup.

Note, I’m assuming I can load my application code on the server side upon startup, instead of passing in the code I want to execute into my Pengines instance like the Scratchpad examples demonstrate. So I don’t want to have HTML code on the client side like:

        <script type="text/x-prolog">

	        q(X) :- p(X).

		    p(a). p(b). p(c). p(d). p(e). p(f). p(g).

        </script>

Instead, using the above sample code, I would want to have already loaded the code to q() and p() on the server side during startup so that the client side code can just call q() without having to define the code it wants my Pengine instance to execute, the code for p() and q() because that code is loaded on the server side during startup.

Do I have this right? Oh heck, after a full day of staring at that code I just got the joke about “minding your P’s and Q’s”. :slight_smile: