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

Errors can be reported as residual goals #6

Closed
triska opened this issue Sep 28, 2022 · 4 comments
Closed

Errors can be reported as residual goals #6

triska opened this issue Sep 28, 2022 · 4 comments
Milestone

Comments

@triska
Copy link

triska commented Sep 28, 2022

For example, in Scryer Prolog, we get:

?- throw(t).
   throw(t).
?- T =.. a.
   error(type_error(list,a),(=..)/2).
?- X =:= Y.
   error(instantiation_error,(is)/2).

Note that exceptions are reported "uniformly" as residual goals, much like constraints and answer substitutions, using the predicates error/2 and throw/1.

This may be worth considering in the API design. It is related to #4.

@guregu
Copy link
Owner

guregu commented Sep 29, 2022

I'm not sure if we can express this in a nice way with the variable substitution format the response currently uses 🤔

IIRC, the way Tau does this is it reports either a map of substitutions or a goal corresponding to the thrown ball, but this leads to kind of an ugly API situation where the response shape can be totally different, so you have to use a helper function (pl.types.is_error in Tau). Being able to switch on the response status is a little bit nicer.

@guregu
Copy link
Owner

guregu commented Sep 29, 2022

I never thought about errors being conceptually the same as residual goals though, that's actually kind of mind blowing, haha.

@guregu
Copy link
Owner

guregu commented Sep 30, 2022

In the latest release you can use the Prolog format to get this.

% demo toplevel looks like this now
?- throw(t).
   throw(t).
?- T =.. a.
   error(type_error(list,a),(=..)/2).
?- X =:= Y.
   error(instantiation_error,number).
const goal = await pl.queryOnce("throw(t).", {format: "prolog"});
// goal = "throw(t)."

@guregu guregu added this to the v1 milestone Oct 8, 2022
@guregu
Copy link
Owner

guregu commented Oct 8, 2022

Closing as done because the Prolog format toplevel report answers the same as regular Trealla now. I would like to further improve the uniformity by splitting the variable dump: #20.

@guregu guregu closed this as completed Oct 8, 2022
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