Replies: 2 comments 1 reply
-
For some reason I thought that you wanted to defer this improvement in errors to after the implementation of the rethrow optimization. So you now think this is beneficial enough to implement even before the optimization? I agree, because this will probably be the greatest improvement in the user experience of Scryer Prolog since the implementation of the toplevel, and it also aligns with Scryer's general philosophy of doing things well before doing them fast. |
Beta Was this translation helpful? Give feedback.
-
This construct seems very valuable! I filed #2846 to make it available in |
Beta Was this translation helpful? Give feedback.
-
Two problems with errors
Insufficient information. The second argument of the
error/2
-term thrown in case of errors is an implementation defined term (7.12.1 The effect of an error) whereas the first argument is one out of the codified error classes in 7.12.2. Often, that error term is a bit too terse — think of an instantiation error which just tells you that some term in some argument of some predicate need to be instantiated further. But you neither know where this happens, nor do you get information of what type that instantiation shall be. Some built-ins at least leave their predicate indicator to take responsibility but then just the innermost place is reported. Think ofwhile the type error is perfect, the
(',')/2
does not give any helpful hint. In some cases some more information is handed over alreadySo
representation_error(dcg_body)
is far too terse, the pairculprit-Culprit
shows the actual culprit.Complex encoding. To better influence this second argument, some of the error reporting facilities include an extra argument to be handed over in case of error (
library(error)
), making the regular code more complex with marginal gains in case of errors.So the idea is to use a list of pairs and add a pair in case of an actual error.
Some keys of such pairs and their values may be:
culprit-Culprit
the actual culprit — should it be representable as a termpredicate-PI
this error occurs within a predicate whose predicate indicator isPI
, likephrase/2
. Note that it does not make sense to associate each and every predicate with such a context, but clean interfaces should do soexpected_type-Type
the type of the insufficiently instantiated termfile-Filename
position-LineNr
this would solve #302: The position prior toread/1
-ing could be reported that way.As a consequence, the errors of
library(error)
should be shortened to the actual error term, like&ct.
A future better implementation might reduce overheads by identifying ground pairs at term-to-body conversion time and allocating them statically. Also, the actual goal
G_0
might avoid being "globalized" thus retaining local variables. And, error-throwing might first identify the active catches and construct the list of pairs without more complex backtracking.Beta Was this translation helpful? Give feedback.
All reactions