how to debug, not understanding safe_primitive

Anne Ogborn <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>

ok, puzzling events occur

First, more important question, is request for advice on debugging pengines application code. At moment this is just sort of 'not running', which is hard to debug. Turning on http debugging gives
 500 ERROR: goal unexpectedly failed: pengine:http_pengine_create([session(1504-0fa0-b94b-f042.Annie-PC),pool(client(httpd@9000,pengine_server:http_dispatch,<stream>(0000000004982960),<stream>(0000000004982870))),peer(ip(127,0,0,1)),protocol(http),input(<stream>(0000000004982960)),method(post),request_uri(/pengine/create),path(/pengine/create),http_version(1-1),host(localhost),port(9000),connection(keep-alive),content_length(164),cache_control(max-age=0),accept([media(application/json,[],1.0,[]),media(text/javascript,[],1.0,[]),media(_G4372/_G4373,[],0.01,[])]),origin(http://localhost:9000),x_requested_with(XMLHttpRequest),user_agent(Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102 Safari/537.36),content_type(application/json; charset=UTF-8),referer(http://localhost:9000/simple.html),accept_encoding(gzip,deflate,sdch),accept_language(en-US,en;q=0.8),cookie([swipl_session=1504-0fa0-b94b-f042.Annie-PC])])

which is somewhat enlightening but not that great.

Second, what have I done wrong?
I wanted to understand how to use safe_primitive/1 to make an API to my code.  To start simple I just made predicate taco/1 that prints debug message added to server.pl

:- module(pengine_server,
  [ server/1% +Port
  ]).
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_server_files)).
:- use_module(library(http/http_files)).
:- use_module(library(pengines)).
:- use_module(library(sandbox)).

:- http_handler(/, http_reply_from_files(web, []), [prefix]).

server(Port) :-
http_server(http_dispatch, [port(Port)]).

:- multifile sandbox:safe_primitive/1.

sandbox:safe_primitive(pengine_server:taco(_)).

taco(X) :-
debug(pengine_example, '~w', [X]).

then added call to it in the simple.html code

<html lang="en">
    <head>
        <script src="/jquery-2.0.3.min.js"></script>
        <script src="/js/pengines.js"></script>
        <script type="text/x-prolog">

// without calling taco on this line it works normally
// when I do call it just sits there - no 'a' response, button gives a 500 code
   q(X) :- p(X),taco('hi').

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

        </script>
        <script>
            var pengine = new Pengine({
                oncreate: handleCreate,
                onsuccess: handleSuccess
            });
            function handleCreate () {
                pengine.ask("q(X)", {
                    template:'X'
                });
            }
            function handleSuccess() {
                $('#out').html(this.data);
            }
        </script>
    </head>
    <body>
        <div>?- q(X).</div>
        <div id="out"></div>

        <button onclick="pengine.next()">Next</button>
    </body>
</html>
-------------- next part --------------
HTML attachment scrubbed and removed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.