Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should the Prolog query format include the dot? #14

Open
guregu opened this issue Oct 1, 2022 · 3 comments
Open

Should the Prolog query format include the dot? #14

guregu opened this issue Oct 1, 2022 · 3 comments

Comments

@guregu
Copy link
Owner

guregu commented Oct 1, 2022

Question for @triska (or anyone):
Let's say I have a query like:

?- between(1,3,X).

And I loop through the results in Prolog format:

for await (const answer of pl.query(`dif(A, B) ; dif(C, D).`, {format: "prolog"})) {
  console.log(answer);
};
// prints:
// "dif(A,B)."
// "dif(C,D)."

Should these results include the fullstop?
I know that regular toplevels will return something like:

dif(A,B) ;
dif(C,D).

But usually we can't know whether it should end in "." or ";" until we loop again.
I was also thinking that returning a result like foo ; isn't useful because it's a partial term.

I made it optional but I'm not sure whether it'd be better to always exclude it, or always include it.
My rationale for including it is I would like each result (that doesn't write to stdout) to be parsable as a Prolog term.

@triska
Copy link

triska commented Oct 1, 2022

An ideal Prolog toplevel follows a simple basic principle:

  1. you put a Prolog term in
  2. in response, you get a Prolog term out that is declaratively equivalent to the original query.

I have uploaded a video explaining queries and answers, I hope it is useful: https://youtu.be/UmGih8xOrJ4

Regarding the syntax of terms, we have:

4.148 read-term: A term followed by an end token.
(see 6.2.2, 6.4.8).

end token (* 6.4.8 *)
   = end char (* 6.4.8 *) ;

end char (* 6.4.8 *) = "." ;

Most importantly: It should be completely clear to users whether they must or must not enter ".". Personally, I think a sensible approach is to require users to enter it, and if it is not entered, somehow display an informational text saying for example: "Write '.' at the end of a query."

@triska
Copy link

triska commented Oct 1, 2022

Regarding layout: ; should never be placed at the end of a line, because it looks so similar to , (which usually occurs at the end of a line).

Scryer Prolog and Trealla use an ideal indentation for answers, for example:

?- dif(A,B) ; dif(C, D).
   dif:dif(A,B)
;  dif:dif(C,D).
?- member(X, "abc").
   X = a
;  X = b
;  X = c
;  false.

@guregu
Copy link
Owner Author

guregu commented Oct 1, 2022

Thanks a bunch! I'll check out the video 👀
I am learning so much :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants