Running queries from Javascript in Swish notebook

#1

EDIT:

Never mind, now it works perfectly for some reason (guess it had to do with reloading the page or something…).

Still, does anybody know where to find more documentation (in addition to the one in the Swish menu Examples > Swish Tutorials)?


Hi!

I am trying to call a query from javascript in a swish notebook. I can’t get it to work. I suspect that the wrong value gets passed to the query grandparent(X, Y) in

G: notebook.$("#theGrandparent").val().

Could anyone help please? As far as I understand this, it is a nested function, is there any way to break this up into steps?

I found some documentation under Help > Notebook in swish, but is there more information somewhere?

Also, whenever i hit the compute button Safari asks me if I want to leave the page… Is there any way to remedy this?

Here is the link to the notebook. Just in case i also added an image below.

I modeled it on Annes clpfd example in the youtube video on playing with prolog. Thanks Anne :slight_smile:

Cheers/JCR

#5

The simplest advice is probably to put what you have on https://swish.swi-prolog.org and explain your problem, so we can all see and edit it. The Prolog implement can be a simple format/2 statement.

2 Likes
#6

Hi!

Here is the link to my swish program (same link as in my original post). The program seems to work now, so I am happy (but if you have additional feedback I would appreciate it).

Thanks!

/JCR

#7

I think that is pretty much ok. I tend to put the menu above the query and re-bind the query play button to get the menu values and run the query. See e.g., Examples/Usage statistics. This is mostly a matter of taste though. Just wanted to hint at the possibility.

1 Like
#8

Thanks for the suggestion!
/JCR

#9

Sorry, but I can’t get this Swish notebook to work (the same as the one in the link above, Javatest5). When i run the query with abe i get false. Also it seems to want to reload the notebook each time i hit the Compute button. I really don’t know what’s going on… If you have time, i would appreciate your help.
Thanks!
/JCR

#10

It reproduced once, but not any more? Normally this is called by JavaScript exceptions or event propagation that eventually causes opening “#”

#11

Thank you for responding Jan.

It reproduced several times both on my windows and mac machines (Firefox and Safari, in Firefox i tried to clear all cookies also before going to swish). Just now, when i tested from Firefox on Windows this happened: Going to the page and directly clicking the Compute button for the first time seems to reload the notebook (it blinks and a blue message appears top right). Clicking Compute again, with abe in the text area, then returns false. When i enter new info in the text field and hit the Compute button, i think the notebook reloads as well.

The other day it was working though, so i really don’t understand what is happening. Sometimes, however, running the query with things that should not unify, e.g. jack also returned true along with different instantiations, e.g. G = "jack", C = bart.

Kind regards, JCR

#12

I’d open the browser console and check for any suspicious messages. That probably gives a hint.

#13

I tried this and I don’t get any messages in the console when running the original program (i can log to the console and make it output errors which i put there on purpose, though).

#14

Solved. Just remove the action="#" from the form. This causes the button-press to finally go to ?grandparent=abc. Stopping event propagation from the click handler probably also works. I’ve updated the notebook.

2 Likes
#15

Thank you very much for your help and patience!
/JCR

#16

@jan I am perplexed :flushed: this notebook stopped working again. When i hit the compute button it just reloads the notebook (i get a blue dialog saying “Opened Javatest5.swinb”. Maybe something with my browser? I have Safari 12.1 on MacOs Mojave…