mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
2.08k stars 125 forks source link

library(error), missing error, module qualification? #1279

Open UWN opened 2 years ago

UWN commented 2 years ago
:- meta_predicate(resource_error(+,:)).
resource_error(Resource, Context) :-
   throw(error(resource_error(Resource), Context)).
triska commented 2 years ago

Is this predicate useful on the Prolog-level? This seems to be an error that would most likely be thrown by the engine itself instead of by Prolog programs (within Prolog code). For example, there seems no way to tell, within Prolog, whether there is sufficient memory to allocate a term. Is there currently a situation where a Prolog program could throw this error by itself and would already benefit from this predicate? Maybe if it itself catches such an error that is generated by the engine, and then wants to throw a resource error itself, is it intended for such situations?

UWN commented 2 years ago

See the definition of length/2. Like length(L,L). Here, it is evident that this computation will take infinitely long. And thus it is legitimate to shorten the time by throwing immediately a resource error.

UWN commented 2 years ago

And what about the module qualification? How else is it possible to tell which definition is meant?

bakaq commented 11 months ago

Like length(L,L). Here, it is evident that this computation will take infinitely long.

I don't understand why this is the case. I think the obvious thing to do here would be to make the predicate fail, because L needs to be both a list and an integer, which is impossible. This doesn't seem to clash with the declarative description of length/2 given here.

UWN commented 11 months ago

This doesn't seem to clash with the declarative description of length/2

Right. But it has undesirable properties when porting a program from one implementation to another. The use of Brent or (previously) Floyd is relatively recent, like 2007. Also, making such an ad hoc improvement, when related predicates don't, seems to be quite odd. Think of ?- append(L,L,L).

And, lest I forget, length(L,L) can only produce that resource error immediately, if L is unattributed.