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

Defined predicates sometimes yield unexpected existence errors #2454

Open
triska opened this issue Jul 21, 2024 · 10 comments
Open

Defined predicates sometimes yield unexpected existence errors #2454

triska opened this issue Jul 21, 2024 · 10 comments

Comments

@triska
Copy link
Contributor

triska commented Jul 21, 2024

For instance, when defining f/0 as:


f :- false, _ is [_|_].

I get:

$ scryer-prolog 
?- [user].
f :- false, _ is [_|_].

   error(type_error(evaluable,'.'/2),load/1).
?- f.
   error(existence_error(procedure,f/0),f/0), unexpected.
   false. % expected

I found this issue based on a recent question on StackOverflow: https://stackoverflow.com/q/78774323

@haijinSk
Copy link

haijinSk commented Jul 21, 2024

I apologize, but to be honest, I have a problem to understand the wording "defined" in the title. If there is an error at the end of defining a predicate, then, from my naive perspective, the existence error is expected, because the predicate is not defined (it was not accepted by the Prolog system).

Or, I suspect, I see it from the wrong point of view, perhaps I completely misunderstood this issue.

@triska
Copy link
Contributor Author

triska commented Jul 21, 2024

In the above example, f/0 is user-defined in the terminology of the Prolog standard:

3.195 user-defined procedure: A procedure which is
defined by a sequence of clauses where the head of each
clause has the same predicate indicator, and each clause
is expressed by Prolog text or has been asserted during
execution (see 8.9).

@haijinSk
Copy link

haijinSk commented Jul 21, 2024

Thank you for the explanation of the term "defined".

I'm an extremely naive user, I simply see: the "defined" predicate is not accepted by the Prolog system in the first place (the system says "type_error", however unexpected here). Therefore I see the "existence_error" as expected. In my perspective, in my "languaging", the unexpected is not accepting the predicate.

@hurufu
Copy link
Contributor

hurufu commented Jul 21, 2024

Updated comment: This is 100% reproducible error starts somewhere around compile_is function. Will try to investigate further.

hurufu added a commit to hurufu/scryer-prolog that referenced this issue Jul 21, 2024
WAM compiler refuses to compile erroneous arithmetic expression, this
causes a premature exception, and failing to add current predicate to
the knwoledge base. For example:

    f :- false, _ is [_|_].

Which has invalid syntax, but has to be executed without exception.
@hurufu
Copy link
Contributor

hurufu commented Jul 21, 2024

Whole loading of a new terms has a few steps. In one of the first steps it tries to expand whatever is possible to expand, and then it tries to compile. There is a special set of functions for handling arithmetic expressions, mainly there is this code that explicitly produces an error when a list (or string) is found. So I think that changing compiler behavior is a bad idea in such case, so I decided to expand away invalid arithmetic expression to throw(error(not_evaluable)). UPD: It is done a little bit differently now.

I have no idea if this is a good place of doing this, but I think general picture is clear.

P.S. It is possible to learn a bit of Rust in one weekend ;)

hurufu added a commit to hurufu/scryer-prolog that referenced this issue Jul 21, 2024
hurufu added a commit to hurufu/scryer-prolog that referenced this issue Jul 21, 2024
hurufu added a commit to hurufu/scryer-prolog that referenced this issue Jul 21, 2024
hurufu added a commit to hurufu/scryer-prolog that referenced this issue Jul 21, 2024
WAM compiler refuses to compile erroneous arithmetic expression, this
causes a premature exception, and failing to add current predicate to
the knwoledge base. For example:

    f :- false, _ is [_|_].

Which has invalid syntax, but has to be executed without exception.
@triska
Copy link
Contributor Author

triska commented Jul 21, 2024

Other arithmetic operations are also affected by this issue. For instance:

f :- false, _ > [_|_].

@triska
Copy link
Contributor Author

triska commented Jul 21, 2024

It's also not limited to [_|_] as the outermost expression. The following also yields an error:

f :- false, _ is 5+[_|_].

@UWN
Copy link

UWN commented Jul 23, 2024

Just a general remark. Fixing this issue currently does not make much sense, because the deeper problem behind is the current representation of partial strings. So fixing this will only delay the transition towards a better representation.

@hurufu
Copy link
Contributor

hurufu commented Jul 23, 2024

Thanks, understood, but it also fails for other kinds of invalid arithmetical expressions, is it also expected?

?- [user].
f :- false, _ is foo.

   error(type_error(evaluable,foo/0),load/1).
?- f.
   error(existence_error(procedure,f/0),f/0).

@triska
Copy link
Contributor Author

triska commented Jul 23, 2024

Just a general remark. Fixing this issue currently does not make much sense, because the deeper problem behind is the current representation of partial strings. So fixing this will only delay the transition towards a better representation.

I think this comment rather applies to #2455 instead of the present issue?

hurufu added a commit to hurufu/scryer-prolog that referenced this issue Aug 3, 2024
WAM compiler refuses to compile erroneous arithmetic expression, this
causes a premature exception, and failing to add current predicate to
the knwoledge base. For example:

    f :- false, _ is [_|_].

Which has invalid syntax, but has to be executed without exception.
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

4 participants